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.
Powershell

Avatar of undefined
Last Comment
DevSupport
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of DevSupport
DevSupport

ASKER

Thank You oBDA!!!
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo