List current snapshots via a script | Nutanix Community
Skip to main content
Solved

List current snapshots via a script


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.

Best answer by andymlloyd

@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
View original
Did this topic help you find an answer to your question?
This topic has been closed for comments

2 replies

  • Voyager
  • 1 reply
  • April 29, 2019
Looks like this may work: https://chrisjeucken.com/2018/07/query-all-snapshots-from-nutanix-ahv/

andymlloyd
Forum|alt.badge.img+2
  • Trailblazer
  • 13 replies
  • Answer
  • August 19, 2019
@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