Monday, February 12, 2018

PowerCLI Script to List VM Snapshots with Last VM Reboot Time

Again, It's time to script, making life easier with the system admin's boring tasks. Most of us have testing environment in which we have to play with snapshots (so called checkpoints in Hyper-V).
This script will list the VMs snapshots with the last VM power-on time. This is particularly useful in cases where you want to keep the snapshot until the VM is rebooted and proved to be fully functional after any configuration changes. So, I put the B4_Reboot column to show 'Yes' if the Snapshot is older than the VM last booted time and 'No' if the snapshot is taken after VM is powered on.


I assumed that you have already connected to vCenter or Esxi. If not, use the following command in PowerCLI.
Connect-VIserver -Server <YourvCenterIP> -Credential (Get-Credential)


Run the script
.\Get_VM_Snapshot_Reboot_Info.ps1


If you want to display the result in table view, run the following command
.\Get_VM_Snapshot_Reboot_Info.ps1 | format-table -auto


If you want to export the result to csv file, run the following command
.\Get_VM_Snapshot_Reboot_Info.ps1 | Export-Csv VM_Snapshots_LastReboot_Info.csv -NoType


You can disconnect the vCenter/Esxi connection after running the script.
Disconnect-VIserver -server <YourvCenterIP>



Get the script from below or from GitHub.


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.