[REQUEST] Comparing services on multiple servers before and after reboot (Part of the code already here)

Hello all,

A fellow redditor was able to help me with part of the code. This code only runs on 1 machine. What i need is a script that will “Get-Content” from a server.txt file listing all the server names. This will take all the services running on the servers.

After that i need to compare it with services running after the machines have been rebooted.

Code:

Run this to create the CSV file for comparison

get-service | Select-Object status,Name,DisplayName,starttype | export-csv "$env:USERPROFILEdocumentsServices.csv" -NoTypeInformation 

After reboot, run what is below

$services = import-csv "$env:USERPROFILEdocumentsServices.csv" $currentServices = get-service | Select-Object Status,Name,DisplayName,starttype for($i=0; $i -lt $services.count; $i ++){ if(Compare-Object -ReferenceObject $services[$i].status -DifferenceObject $currentServices[$i].status){ [pscustomobject]@{ service=$services[$i].name; PreviousStatus=$services[$i].Status; CurrentStatus=$currentServices[$i].status } } 

}

submitted by /u/machina0101
[link] [comments]

Leave a Reply