Help with get-content

Welcome Forums General PowerShell Q&A Help with get-content

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years ago.

  • Author
  • #5324

    Points: 0
    Rank: Member

    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?.



    $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


    How about this for a starter:

    {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.

    service1 started
    service2 started

    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"}

The topic ‘Help with get-content’ is closed to new replies.