Solved

List current snapshots via a script

  • 29 April 2019
  • 2 replies
  • 5366 views

Hi,
I`m very new to Nutanix and have a question.

Does anyone know if there is a way to list all current snapshots via a script?

I`d like to find out if there are any lingering snapshots that should be removed.

Thanks for any advice you might have.
icon

Best answer by andymlloyd 19 August 2019, 13:45

View original

This topic has been closed for comments

2 replies

Userlevel 2
Badge +2
@nfrederickx Hi,

You can get a very simple output of VM Name, VM Snapshot Name and Date/Time taken using the Powershell Cmdlets. Script below should sort you out:

## Simple Nutanix All Last Snapshot info Script ##
## Andy Lloyd ##

$nutsnaps=Get-NTNXSnapshot
$allnutvms=Get-NTNXVM | select uuid,vmName
foreach ($snap in $nutsnaps)
{
$vmname= ($allnutvms | where {$_.Uuid -eq $snap.vmUuid}).vmName
$snaptime=$snap.createdtime/1000
$snapdt=(Get-Date '1/1/1970').AddMilliseconds($snaptime)
$actualsnapdt=$snapdt.ToLocalTime()
##Write-host $actualsnapdt
#Write-host $snap.snapshotname
Write-host "VM: " -nonewline; write-host $vmname -foregroundcolor yellow -nonewline; Write-Host " Last Snapshot Name: " -nonewline; `
write-host $snap.snapshotname -foregroundcolor Yellow -nonewline; Write-Host " Taken: " -nonewline; Write-host $actualsnapdt -foregroundcolor Yellow
}

If this helps you out please mark as Best Answer and Like 🙂
Many thanks
Andy
Looks like this may work: https://chrisjeucken.com/2018/07/query-all-snapshots-from-nutanix-ahv/