Query all snapshots from Nutanix-AHV

Introduction:
While working in a Nutanix-AHV environment I wanted to list all snapshots in the environment. With VMware vSphere you needed to do this with PowerCLI or use the excellent RVTools. In Nutanix Prism you can (to my knowledge) only see the snapshots when opening the virtual machine details.

Going through every VM in this environment would cost precious time that could also be spent drinking coffee, going through Twitter or catching up on some sleep. So I created the following script to list all snapshots in your environment, the virtual machine it belongs to and when it was created.

The script:

Just copy the code below to your PowerShell editor of choice (Visual Studio Code FTW) and save it as a .ps1 file or download the Zip file.

Fill in the NTNXCluster variable with the Fully Qualified Domain Name / Hostname or IP address of your Nutanix Cluster(s) (divide multiple with a semicolon (;)) and add any exceptions if needed. Also make sure you have the Nutanix Cmdlets installed on your system (which of course you have already).

After that run the .ps1 file and it will ask for credentials which it will use to connect to the Nutanix Cluster and retrieve the snapshot information.

The actual script:

DISCLAIMER: Once again: I’m in no way an expert PowerShell scripter, so it might not be the most efficient code, but it gets the job done. And, of course, feel free to use it/alter it/publish it as your own.

 3,806 total views,  8 views today

5 thoughts on “Query all snapshots from Nutanix-AHV

  1. Deniece Greenwood

    Love this! One thing: I don’t get the VM-Name. See below.(sorry ~ format)

    VM-Name Snapshot-Name Creation-Time
    ——- ————- ————-
    nNSVPXd – Before CVE-2019-19781 12/26/2019 5:04
    n10GoldStaff1809 – 10.31.19 – WEM 1906 10/31/2019 11:46
    Apps – FileZille 3.36.0 9/12/2018 13:44
    nNSVPXa – Backup 2 11/28/2017 20:18
    nSRNPro-B4FebUpdts 2/18/2020 17:39
    nSRFSB-B4FebUpdts 2/18/2020 18:02

    Second thing: (see how I am? 🙂 )
    How to put to file, Export-CSV instead of Format-Table?

    Thanks

    Reply
    1. Chris Jeucken Post author

      Deniece,

      Thanks for the feedback. 🙂
      That’s strange.
      Maybe some things changed in the CMDlets.
      Sadly I don’t have access to a Nutanix environment right now, so I am unable to test it for you.
      In the following lines retrieve the VM-name.
      $VMUuid = $Snapshot.vmUuid
      $VMname = ($AllNTNXVM | Where-Object {$_.Uuid -eq $VMUuid}).vmName

      After running the script, could you try running these lines this way? (To see if it gives output)
      It should use the last snapshot in the foreach loop.
      $VMUuid = $Snapshot.vmUuid
      ($AllNTNXVM | Where-Object {$_.Uuid -eq $VMUuid}).vmName

      As for the export:
      You could just change the last line from:
      $Results | Format-Table
      to
      $Results | Export-Csv -Path *Filename*

      Let me know if that works for you.

      Greetings,
      Chris

      Reply
      1. Deniece Greenwood

        Sorry I missed it the first time around: timeout have something to do with it?

        PS C:\Users\SU2> C:\Scripts\NTNX\Query-all-snapshots-Nutanix-AHV.ps1
        Get-NTNXVM : The operation has timed out
        At C:\Scripts\NTNX\Query-all-snapshots-Nutanix-AHV.ps1:63 char:18
        + $AllNTNXVM = Get-NTNXVM -ErrorAction SilentlyContinue
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : InvalidArgument: (Nutanix.Prism.Common.NutanixCluster:NutanixCluster) [Get-NTNXVM], WebException
        + FullyQualifiedErrorId : Error,Nutanix.Prism.PS.Cmds.Vmmanagement.GetVM

        VM-Name Snapshot-Name Creation-Time
        ——- ————- ————-
        nNSVPXd – Before CVE-2019-19781 12/26/2019 5:04:46 AM
        n10GoldStaff1809 – 10.31.19 – WEM 1906 10/31/2019 11:46:06 AM
        Apps – FileZille 3.36.0 9/12/2018 1:44:17 PM

        Reply
  2. Leonardo Almeida

    Script works fine, thanks a lot.

    By the way do you know the Nutanix recommendation for keep a VM snapshot?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *