Script Sample - Check for Pending Reboots on various VMs in your environment@20aman Oct 15, 2018
Often times you will need to check if there are any VMs/Servers in your environment which have Pending Reboot on them. You will want to schedule and perform a planned reboot on these VMs after going through proper processes.
The script sample in this post is about checking multiple Vms in your environment and check if there is any Pending Reboot on any of the VMs. The script uses WMI queries to check if there is any pending reboot on the machine.
This script was not authored by me. I received it from one of my colleagues and I couldn't track the original author of this script. Nevertheless, this is a very useful script for system administrators.
The script can be used as shown below:
C:\Users\aman\Downloads> import-module .\Get-PendingReboot.ps1 C:\Users\aman\Downloads> $Servers = Get-Content C:\Users\aman\Downloads\Servers.txt C:\Users\aman\Downloads> Get-PendingReboot -Computer $Servers | Export-Csv C:\Users\aman\Downloads\PendingRebootReport.csv -NoTypeInformation
In the 2nd command above, the Server.txt file should simply have the list of names of the computers in your environment with one computer name per line.
Location of the Script
You can find this script in GitHub at this location: Get-PendingReboot.ps1