Skip to content

Instantly share code, notes, and snippets.

@nshores
Last active April 23, 2018 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nshores/7dfb18619ed019f5cc47cb15a98e1ae1 to your computer and use it in GitHub Desktop.
Save nshores/7dfb18619ed019f5cc47cb15a98e1ae1 to your computer and use it in GitHub Desktop.
get-allvmsnapshot.ps1
<#
.Synopsis
Scans for all snapshots including hidden ones on all VM's, or selected ones.
.Description
Returns a list of snapshots that include hidden and visible ones. Invisble snapshots are considered snapshots that can only be found by searching the VMFS file system for *delta* files.
Pipeline support is included.
.Example
get-allvmsnapshot
Returns the total number of snapshot related files in the envionrment as well as a list of VM's with hidden snapshots.
get-allvmsnapshot -vm myguestvm
Returns snapshot information about selected vm.
.Link
#>
function get-allvmsnapshot {
[CmdletBinding()]
Param (
[Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName, Position=0)][Alias('Name')]
[string[]]$VM = '*'
)
$final = @()
$snapshotfinal = @()
$vmlist = get-vm $VM
#Get a list of all VM's with known snapshots
foreach ($v in $vmlist){
if (get-snapshot $v){
$snapshotfinal += $v.name
}
}
#Get all VM's with delta disks
foreach ($v in $vmlist){
$delta = $v.extensiondata.layoutex.file | where-object {$_.Name -like "*delta*"} | select-object -first 1
if ($delta){
$final += $v.name
}
}
#Compare $Final with $snapshots
$vcount = $snapshotfinal.count
$icount = $final.count - $snapshotfinal.count
Write-Output "Total number of VM's with visible snapshots: $vcount"
write-output "Total number of VM's invisible snapshots: $icount"
write-output "`nYou have hidden snapshots on the follow VM's:`n"
$diff = Compare-Object $final $snapshotfinal | ?{$_.SideIndicator -eq '<='} | select InputObject
foreach ($d in $diff){write-output $d.inputobject}
}
get-allvmsnapshot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment