Link to home
Start Free TrialLog in
Avatar of DevSupport
DevSupport

asked on

Getting get-service results from remote system into script variables

I am trying to get the results from a command Get-Service remotely and get the "status" result into a text box.

When I do Get-Service -DisplayName "windows audio" locally

I get

Status   Name               DisplayName                          
------   ----               -----------                          
Running  AudioSrv           Windows Audio

I would like to run it remotely using invoke-command and obtain the "Running" into an array or something, so that I can show in text box.

When I try the below I get $AppState as Name or "Audiosrv", but I am unable to get the Status value into array.

$AppState = Invoke-Command -Computername $objappsvrname.Text -ArgumentList $dispname -ScriptBlock {Param($DisplayName); Get-Service -DisplayName $DisplayName}


Please let me know how I can get the  status "Running" into $AppState

Please let me know if you need more info.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DevSupport
DevSupport

ASKER

Thank You oBDA!!!