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
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.
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.
Ok,
I'll give it a try.
Thanx.
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 -AutoSizeJoe
- Edited by joe keohan Wednesday, May 23, 2012 1:54 PM
- Marked as answer by Yan Li_Microsoft contingent staff, Moderator Monday, May 28, 2012 2:35 AM
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 -AutoSizeJoe
- Edited by joe keohan Wednesday, May 23, 2012 1:54 PM
- Marked as answer by Yan Li_Microsoft contingent staff, Moderator Monday, May 28, 2012 2:35 AM
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 -AutoSizeJoe
- Edited by joe keohan Wednesday, May 23, 2012 1:54 PM
- Marked as answer by Yan Li_Microsoft contingent staff, Moderator Monday, May 28, 2012 2:35 AM
How do I get an output with not only the
Status, Name, DisplayName
But also the corresponding Server running the service?
Thanks
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.
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
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
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
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 | foreach { (Get-Service -Name Yourservicename -computername $_) |
Select-Object Status, Name, DisplayName, MachineName } | Export-csv -Path C:\Users\Lg167978\Desktop\Service.csv
==========================
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}