Get services from remote computers
Hi all,

Insted of logging to every computer and to check if the sms service is running, i decided to create a powershell script. this script will get the name of the remote computers, and give me the putput result in HTM frmat.

So far i managed to get it going only with one computer every at a time, unfortunatlly the powershell help didn't help me as  thought.

this is the batch i'm using right now.


Get-Service ccm* -computername pc2367 | Select-Object Status, Name, DisplayName | ConvertTo-HTML | Out-File C:\Test\Test.htm
Invoke-Expression C:\test1\Test.htm

How can i modify it to get the result from multiple computers that i use in a txt file?

Please advise,

Best regards,

Nahum
May 23rd, 2012 8:33am

Hello Eliash.

I recommend to import the server names from a textfile:

$server = Get-Content -path C:\User\Test\Desktop\...

After that you are going through a foreach-loop to execute the code for each server:

$server | foreach { (Get-Service -Name ccm* -computername $_) |

Select-Object Status, Name, DisplayName |

ConvertTo-HTML | Out-File "C:\Users\test.htm"}

Under the following link you will find additional approaches to connect to a remote computer:

http://technet.microsoft.com/en-us/library/dd819505.aspx

Hope I could help you.

Free Windows Admin Tool Kit Click here and download it now
May 23rd, 2012 9:22am

Hello Junior,

So, first of all i need to make a list of all the servers i want to run the script on, and then the $server (command) will get the names from the txt file and run the command?

Best regards,

Nahum.

May 23rd, 2012 11:02am

Exactly the text file should contain one server each line and nothing else :)
Free Windows Admin Tool Kit Click here and download it now
May 23rd, 2012 12:26pm

Ok,

I'll give it a try.

Thanx.

May 23rd, 2012 1:01pm

Nahum,

Give this a try...It will create a custom object with the Service Name,Status and Computer Name...

$array = @()            
foreach($i in (gc c:\computers.txt)) {            
 $svc = Get-Service winrm -ComputerName $i -ea "0"            
 $obj = New-Object psobject -Property @{            
  Name = $svc.name            
  Status = $svc.status            
  Computer = $i            
  }            
 $array += $obj            
}                      
$array | Select Computer,Name,Status | FT -AutoSize
Joe
Free Windows Admin Tool Kit Click here and download it now
May 23rd, 2012 1:35pm

Nahum,

Give this a try...It will create a custom object with the Service Name,Status and Computer Name...

$array = @()            
foreach($i in (gc c:\computers.txt)) {            
 $svc = Get-Service winrm -ComputerName $i -ea "0"            
 $obj = New-Object psobject -Property @{            
  Name = $svc.name            
  Status = $svc.status            
  Computer = $i            
  }            
 $array += $obj            
}                      
$array | Select Computer,Name,Status | FT -AutoSize
Joe
May 23rd, 2012 1:35pm

Nahum,

Give this a try...It will create a custom object with the Service Name,Status and Computer Name...

$array = @()            
foreach($i in (gc c:\computers.txt)) {            
 $svc = Get-Service winrm -ComputerName $i -ea "0"            
 $obj = New-Object psobject -Property @{            
  Name = $svc.name            
  Status = $svc.status            
  Computer = $i            
  }            
 $array += $obj            
}                      
$array | Select Computer,Name,Status | FT -AutoSize
Joe
Free Windows Admin Tool Kit Click here and download it now
May 23rd, 2012 1:35pm

How do I get an output with not only the

Status, Name, DisplayName

But also the corresponding Server running the service?

Thanks

September 30th, 2013 8:59pm

Hi,

Add a parameter to the object and use the computer name that is currently being run though the loop as the value.

If you have more questions, I recommend starting a new thread.

Free Windows Admin Tool Kit Click here and download it now
September 30th, 2013 9:04pm

Hi,

# just create a file that content the list of server
# you can of cause use notepad to create it.
 echo lon-svr1 >c:\computers.txt
 echo lon-svr2 >>c:\computers.txt
 $server = Get-Content -path computers.txt

# and use '|' to do the job, put it in a csv file
get-service -computername $server |
 select machinename, name, status |
 sort machinename |
 ConvertTo-Csv | Out-File "C:\ServerBycomputer.csv"




  • Edited by xDaudaudau Friday, October 04, 2013 9:06 PM
October 4th, 2013 9:03pm

Hi,

# just create a file that content the list of server
# you can of cause use notepad to create it.
 echo lon-svr1 >c:\computers.txt
 echo lon-svr2 >>c:\computers.txt
 $server = Get-Content -path computers.txt

# and use '|' to do the job, put it in a csv file
get-service -computername $server |
 select machinename, name, status |
 sort machinename |
 ConvertTo-Csv | Out-File "C:\ServerBycomputer.csv"




  • Edited by xDaudaudau Friday, October 04, 2013 9:06 PM
Free Windows Admin Tool Kit Click here and download it now
October 4th, 2013 9:03pm

Hi,

# just create a file that content the list of server
# you can of cause use notepad to create it.
 echo lon-svr1 >c:\computers.txt
 echo lon-svr2 >>c:\computers.txt
 $server = Get-Content -path computers.txt

# and use '|' to do the job, put it in a csv file
get-service -computername $server |
 select machinename, name, status |
 sort machinename |
 ConvertTo-Csv | Out-File "C:\ServerBycomputer.csv"




  • Edited by xDaudaudau Friday, October 04, 2013 9:06 PM
October 4th, 2013 9:03pm

Hi King,

Thanks a lot. Really helped. But the script has some output issues where the output is reedited and only one server name appears.

If you see after few seconds the server name changes where the it ran the script.

I altered to an extent and now it gives the output correctly.

==========================

$server = Get-Content -path C:\Users\Lg167978\Desktop\Servers.txt
$server | foreach { (Get-Service -Name Yourservicename -computername $_) |
Select-Object Status, Name, DisplayName, MachineName } | Export-csv -Path C:\Users\Lg167978\Desktop\Service.csv

==========================

Free Windows Admin Tool Kit Click here and download it now
June 17th, 2015 7:59am

I did much searching and found this page.

For my purposes, I just wanted something quick to run.

Finds service windows remote management, on servers in active directory with name that contains WDS

$gs=get-service -name WinRM

$machines=Get-ADComputer -filter 'name -like "*wds*"'|%{$_.name}

ForEach-Object {Invoke-Command -computername $machines -scriptblock $gs}

June 19th, 2015 5:08pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics