<#Created By Abhishek Bansal
Read Note
Script Usage :: Validation Script, Useful in Comparing Windows Services Status before & after reboot.
Pre requisites :: Copy all the code into a text file, save it with an extension ".PS1". Once saved, run it as Administrator. You need to run this script twice, first prior reboot with Option 1 and second time will be after rebooting with option 2.
Execution & Outputs :: Once executed, there will be two files created as BeforeRestart.csv containing Services status before reboot & one with name AfterRestart.csv containing Services status post reboot. Differences among both the files will be visible directly on the console in Red color. #>
Write-Host -ForegroundColor Yellow "`nPress 1 to fetch services status before reboot"
Write-Host -ForegroundColor Yellow "Press 2 to fetch services status after reboot & proceed with validations.."
$choice = Read-Host "`nEnter your choice = "
if($choice -eq 1)
{
Get-Service | Select Name,DisplayName,Status | Export-Csv ./BeforeRestart.csv -NoTypeInformation
}
elseif($choice -eq 2)
{
Get-Service | Select Name,DisplayName,Status | Export-Csv ./AfterRestart.csv -NoTypeInformation
$Beforerestartdata = Import-Csv .\BeforeRestart.csv
$Afterrestartdata = Import-Csv .\AfterRestart.csv
#Comparing Services.....
foreach($row in $Beforerestartdata)
{
foreach($row1 in $Afterrestartdata)
{
if($($row.Name) -eq $($row1.Name))
{
if($($row.Status) -eq $($row1.Status))
{
Write-Host "$($row.Name) seems fine" -ForegroundColor Green
}
else
{
Write-Host "$($row.DisplayName) service is having differences. Before Reboot Status was $($row.Status) and after reboot status is $($row1.Status)" -ForegroundColor Red
}
}
else
{
continue
}
}
}
}
else
{
Write-Host "Invalid Choice..."
}
No comments:
Post a Comment