Search code examples
powershellpowershell-remoting

PowerShell cmdlet get-service returns different results remotely


If I run the following command remotely from a server it returns a list of 37 services.

get-service -computername <computer name>

If I connect to the remote host and run the same command through a remote session it returns a list of 161 services.

new-pssession <computer-mame>
enter-pssession <session id>
get-service

can anybody point to me to an explanation please?


Solution

  • I cannot reproduce your result. Try the following snippets:

    $ComputerName = 'ComputerName'
    
    $ServiceList = Get-Service -ComputerName $ComputerName
    $ServiceList.count
    
    $PSSession = New-PSSession -ComputerName $ComputerName
    Invoke-Command -Session $PSSession -ScriptBlock {
        $ServiceList = Get-Service
        $ServiceList.count
    }