This question was asked a few times before but I could not find a solution to my scenario in any of them.
Basically I need the script to continue after it reboots if needed. It will check a few registry keys and will determine if the machine needs to be rebooted.
I tried using 'workflow' in various ways but could not get it to work successfully.
Here is the rough description of my code:
function (check-if-computer-needs-a-reboot){
if(this and that)
try{
return $true
}
catch{}
return $false
}
if(check-if-computer-needs-a-reboot = $true){
Write-Host "The machine is rebooting..."
Restart-Computer -Wait -Force
Write-Host "The machine was successfully rebooted"
}
else
{
Write-Host "No pending reboot"
}
Hoping the wizards of Stack-overflow can help.
Any help will be greatly appreciated!!!