Hi, try this:
################################
#
# PowerCLI script with list of all Snapshots
# Created by Jiri Luska on 21/07/2016 @EmbedIT
#
################################
Write-Host "List of Snapshots on vCenters - script by Jiri Luska @EmbedIT"
Write-Host ""
Write-Host -NoNewline "Searching for Snapshots"
$Report = Get-VM | Get-Snapshot | Select @{N="vCenter";E={$($_.Parent.Client.ServerUri).TrimStart("443@")}},VM,Name,Description,@{Label="Size";Expression={"{0:N2} GB" -f ($_.SizeGB)}},Created
Write-Host " - DONE"
If (-not $Report)
{ $Report = New-Object PSObject -Property @{
vCenter = ""
VM = "No snapshots found on any VM's"
Name = ""
Description = ""
Size = ""
Created = ""
}
}
$Report | Select vCenter,VM,Name,Description,Size,Created | Out-GridView
#export-csv c:\ps\list-snap.csv -NoTypeInformation
Also if you are interested in delete all snapshots older than 14 days and keep ones which have in name "do not delete", you can use this:
(remove Whatif :-) to get rid of DEMO MODE)
################################
#
# PowerCLI script with action to remove all 14 days old snapshots except ones with mark "do not delete"
# Created by Jiri Luska on 21/07/2016 @EmbedIT
#
################################
Write-Host "Remove 14 days old Snapshots from vCenters - script by Jiri Luska @EmbedIT"
Write-Host ""
Write-Host -NoNewline "Searching for Snapshots"
$SometimeAgo = (Get-Date).AddDays(-14)
$Snap = Get-VM | Get-Snapshot
Write-Host " - DONE"
Write-Host ""
Write-Host "Performing remove: DEMO MODE"
ForEach($VMHost in $Snap)
{
if ($VMHost.Created -lt $SometimeAgo) {
if ($VMHost.Name -like "*do not delete*") {
Write-Host "Shipping marked snapshot: " $VMHost.VM.Name " - " $VMHost.Name
} else {
Write-Host "Removing snapshot: " $VMHost.VM.Name " - " $VMHost.Name
Remove-Snapshot $VMHost -Confirm:$false -WhatIf
}
}
}