Reputation: 107
Using PowerShell, if I run this command on my local computer, the output is "Running"
(Get-Service -Name Spooler).Status
If I run the same command inside an Invoke-Command script block, to get the status of the service on a remote computer
Invoke-Command -ComputerName 10.131.173.71 -Credential $cred -ScriptBlock {(Get-Service -Name Spooler).Status}
the output is
PSComputerName RunspaceId Value
-------------- ---------- -----
10.131.173.71 5f1b9d02-4c60-47a9-b783-01fa89eb1d58 Running
How can I get the same output with the second command? (Running)
Upvotes: 1
Views: 166
Reputation: 61128
Here is one way to do it. You don't get the same value when remoting because the Status
Property is an enum and it gets de-serialized that way. See this answer for more details.
[ServiceProcess.ServiceControllerStatus] (
Invoke-Command -ComputerName 10.131.173.71 -Credential $cred -ScriptBlock {
[int] (Get-Service Spooler).Status
}
)
Upvotes: 2