Get-Service on Multiple Remote Computers

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

Get-Service *vault* -ComputerName (Get-Content c:\users\sean\desktop\js.txt) | select name,status,machinename | sort machinename | format-table -autosize 
+4
source share
8 answers

Try without get-content . Try the following:

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

If this does not work, 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 want a single line font, try the following:

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

At first I tried the top one. I would check, but I do not have access to everything that I can do with proper testing right now.

+6
source
 $Computers = get-content .\desktop\test.txt $Service = "Vault" foreach ($computer in $computers) { $computer $Servicestatus = get-service -name $Service -ComputerName $computer } $Servicestatus | select-object Name,Status,MachineName | format-table -Autosize 

This works for me, it gives me each of the computers in a text file and is looking for a service.

+3
source

This is what I use. I get a list of computers from OU to AD.

 Import-Module ActiveDirectory $ou = "OU=Servers,DC=Domain,DC=com" $servers = Get-ADComputer -Filter * -SearchBase $ou | select-object -expandproperty name Foreach ($server in $servers){ $Data = Get-Service -ServiceName *IIS*,*TomCat*,*httpd* -ComputerName $server | select machinename,name | sort machinename | format-table -AutoSize Write($Data) | Out-File .\WebServices.txt -Append } 
+2
source
 $servers = Get-Content .\servers.txt Foreach ($server in $servers) { "$server" Get-Service -ComputerName $Server -name -like "*vault*" "-------------------" } 
+1
source

Following the memory limit limitation with older versions of PowerShell, I had to update my code:

Old code: gwmi win32_service -computer $ allcomputers | Select-Object __SERVER, Name, state, startmode, StartName

New code:

`$ servers = Get-Content" computers.txt "Foreach ($ server in $ servers) {

Get-WmiObject -Class WIN32_service -ComputerName $ server | Select-Object __SERVER, Name, state, startmode, StartName | Export-Csv -path "Report.CSV" -NoTypeInformation -Append

} `

+1
source

Get-Service -ComputerName ... has an error in PowerShell 2.0 that only returns the first computer. This has been fixed in newer versions, so if you upgrade to PowerShell 3.0 or later, the source code will work fine.

As a workaround, use the foreach-loop to run Get-Service once for each computer:

 Get-Content c:\users\sean\desktop\js.txt | ForEach-Object { Get-Service -Name *vault* -ComputerName $_ } | Select-Object -Property Name, Status, MachineName | Sort-Object -Property MachineName | Format-Table -AutoSize 
0
source

Here's how you can get a list of all the services in your AD domain:

 Get-ADComputer -Filter {OperatingSystem -Like "Windows 10*"} | ForEach-Object {Get-WmiObject -Class Win32_Service -Computer $_.Name} 

More useful examples of this (get a list of services for all computers listed in a text file, etc.): https://www.action1.com/kb/list_of_services_on_remote_computer.html

0
source

Nick's solution doesn't completely work for me. I ended up writing a quick and dirty one that works:

 $servers = Get-Content .\servers.txt Foreach ($server in $servers) { "$server" Get-Service *vault* "-------------------" } 
-1
source

Source: https://habr.com/ru/post/1435324/


All Articles