Get VM Snapshots via Powershell
This is a little script / scriptlet I came up with when working at my old MSP. We unfortunately had employees who had the tendency to create snapshots in Windows Server and Hyper-V and then leave them. For long periods of time. As in months and even a year plus. These snapshots would grow and of course be a pain in the butt to merge and get rid of.
I ran this in our RMM tool and was able to set an alert or report to it. If there are no snapshots, it exits successfully (Exit 0). If there are snapshots, it says how many there are and exists with a code 1001. You can then have your RMM or log checker alert on that code.
$results=get-vmsnapshot -vmname * | Select VMName, Name, CreationTime
$count=$results | measure | Select Count
If ($count.Count -eq 0)
{Write-Host "No snapshots found"
Exit 0}
Else {Write-Host $results.VMName 'has' $count.Count 'snapshots'
Exit 1001}