We help IT Professionals succeed at work.

Getting get-service results from remote system into script variables

DevSupport
DevSupport asked
on
66 Views
Last Modified: 2017-03-20
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.
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Thank You oBDA!!!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions