Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get-Service on multiple remote machines

Tags:

powershell

I can only get the command to return the services on the first computer in the text file. Is there a better way than for-each for this task?

Get-Service *vault* -ComputerName (Get-Content c:\users\sean\desktop\js.txt) | select name,status,machinename | sort machinename | format-table -autosize
like image 706
Whiskey Bob 98 Avatar asked Sep 20 '12 16:09

Whiskey Bob 98


People also ask

How do I run a service on a remote computer?

Getting Remote Services With Windows PowerShell, you can use the ComputerName parameter of the Get-Service cmdlet to get the services on remote computers. The ComputerName parameter accepts multiple values and wildcard characters, so you can get the services on multiple computers with a single command.

How do you check if a service is running or not on multiple servers?

Windows natively has a command line tool which can be used to check if a service is running or not on a remote computer. The utility/tool name is SC.exe. SC.exe has parameter to specify the remote computer name.

How do I find services on a remote computer?

Use PowerShell to Check Service Status on a Remote Computer You can use the Get-Service cmdlet to get the status of services not only on the local but also on remote computers. To do this, use the –ComputerName parameter. You can use the NetBIOS, FQDN name, or an IP address as a computer name.


1 Answers

Try it without the get-content. Try this:

Get-Service *vault* -ComputerName c:\users\sean\desktop\js.txt | select name,status,machinename | sort machinename | format-table -autosize

If that doesn't work, then try:

$Computers = Get-Content c:\users\sean\desktop\js.txt
Get-Service *vault* -computername $Computers | Select name,status,machinename |sort machinename |format-table -autosize

If you are eager for a one-liner then try this:

Get-Content c:\users\sean\desktop\js.txt | Get-Service *vault* | Select name,status,machinename |sort machinename |format-table -autosize

I would try the top one first. I would test, but I don't have access to anything I can do a proper test right now.

like image 173
Nick Avatar answered Nov 01 '22 23:11

Nick