# Help with get-content

by mbuk at 2012-12-06 05:02:20

Hi, i want to check if an services have not re started after rebooting some servers. so i thought i’d run this before and after. What i can’t work out is how to add the server name before it lists the services for each entry. i just get a long list of services. Any ideas?.

Thanks

Andrew

$colComputers = get-content C:\scripts\servers1.txt foreach ($StrComputers in $colComputers) {Get-Service -Computername$StrComputers | ConvertTo-HTML | Out-File C:\scripts\info.html}
by ArtB0514 at 2012-12-06 06:45:11
Several.

{Get-Service -Computername $StrComputers | ConvertTo-HTML | Out-File "C] by mbuk at 2012-12-06 07:21:23 Ineresting. But what i am after is all in one files something like below so that i can do a compare on the files 9before and after reboot) and find whats changed. So i need to inject the$StrComputers into the output file between each iteration of get-service. hope this makes sense so i know on which server the service has stopped on.

myserver
service1 started
service2 started

myserver2
service1 started
service2 started
by mbuk at 2012-12-06 07:29:30
forgot to say thank for the reply so far.
by mbuk at 2012-12-06 09:03:39
This seems to work. i just change the out-file path after the reboot and then compare the two files.

$colComputers = get-content C:\scripts\servers1.txt foreach ($StrComputers in $colComputers) {$StrComputers.toUpper() | Out-File -Append "C:\Scripts\server1.txt"
Get-Service -Computername $StrComputers | where-object {$_.Status -eq “Running”} | Out-File -Append “C:\Scripts\server1.txt”}