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.
DevSupportAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
Your command will return an object with the usual properties, and you can access them the same way you would with a local execution:
$AppState.Status
Or you can do it on the remote side if you only want the Status:
$AppState = Invoke-Command -Computername $objappsvrname.Text -ArgumentList $dispname -ScriptBlock {Param($DisplayName); (Get-Service -DisplayName $DisplayName).Status}

Open in new window

Or like this:
$AppState = Invoke-Command -Computername $objappsvrname.Text -ArgumentList $dispname -ScriptBlock {Param($DisplayName); Get-Service -DisplayName $DisplayName | Select-Object -ExpandPoperty Status}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DevSupportAuthor Commented:
Thank You oBDA!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.