|
PowerCLi List all Snapshots older then x days.
A script to scan all VMs and list Snapshot data such as age, size, creation date and desciption.
# List all snapshots older the $Age days old # and List all snapshots over $SnapSize Mb # Output to screen and text file called $OutPutFile # connect to vCenter server $VServer $Age = 0 $SnapSize = 3 $OutPutFile = result.txt $VServer = Your.vCenter.server.name.here
# Loads the VCenter snapins if not loaded if (get-pssnapin vmware*) {Write-Host vSphere snapin loaded, running script } else { clear-host Write-Host Loading vSphere snapin. Add-pssnapin VMWare.VimAutomation.Core Write-Host Loaded, running script }
Connect-VIServer $VServer $headertext = "Snapshot info" | out-file $OutPutFile $vmlist = Get-VM
foreach ($VM in $VMlist) { $Snap = get-snapshot -VM $VM if ($snap.SizeMB -gt $SnapSize) { if ( $snap.Created -lt (Get-Date).AddDays( -$Age ) ) { $DSName=get-datastore -vm $VM.name Write-Host "VM: " $VM.name " Snap Name: " $snap.Name " Size: " $snap.SizeMB " Created: " $snap.Created " DS Name: " $DSName $OutPuttext = "VM: "+ $VM.name +" Size: "+ $snap.SizeMB +" Created: "+ $snap.Created +" Snap Name: "+ $snap.Name + " DS Name: " + $DSName | out-file $OutPutFile -append } }
}
Disconnect-VIServer -Confirm:$False
Write-Host "Press any key to continue ..." $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
|
|
DownLoade Code
The code displayed above has lost its indents. you are better off downloading the PS1 file then copy and pasting.
|
|
|
|
Links
Welcome Page
o Galleries
o Diving
o Caving
o Computing
o Personal
o SiteMap
Snipits from the Galleries
|
|