2 Replies Latest reply on Jun 13, 2012 12:58 PM by Zsoldier

    Phantom Snapshot found for a non-existent vm.

    Zsoldier Expert
    vExpert

      Wondering if anyone as run into this.  I have a script that checks Snapshots daily using the Get-View cmdlet like so:

       

      $AllSnapShots = Get-View -ViewType virtualmachine -Property snapshot -Filter @{"Snapshot"="VMware.Vim.VirtualMachineSnapshotInfo"}
      $Snapshots = @()
      Foreach ($Snap in $AllSnapShots){
      $Snapshots += $Snap.snapshot.rootsnapshotlist
      }
      $Aged = $Snapshots | where {$_.CreateTime -lt ((Get-Date).AddDays(-$SnapshotAge))} 
      $NewSnapData = @()
      Foreach ($Snapshot in $Aged){
      $NewDataSet                = "" | Select VM, Name, DaysOld, Created, Description
      $NewDataSet.VM                = Get-VM -Id $Snapshot.VM
      $NewDataSet.Name           = $Snapshot.Name
      $NewDataSet.DaysOld      = ((Get-Date)-($Snapshot.CreateTime)).Days
      $NewDataSet.Created          = $Snapshot.CreateTime
      $NewDataSet.Description = $Snapshot.Description
      $NewSnapData += $NewDataSet
      }
      

      What I'm finding is that there appears to be a phantom entry in my $NewSnapData Object.

      It appears to have data associated to a VM that no longer exists.

       

      I'm wondering if it's an entry I have to find in the SQL database and manually delete it.

      I end up w/ an entry that looks like this:

      VM          :

      Name        : TEST

      DaysOld     : 418

      Created     : 4/21/2011 6:25:10 PM

      Description :

       

      I do see an error when running it manually and the vm id it's trying to query for vm name.

       

        • 1. Re: Phantom Snapshot found for a non-existent vm.
          LucD Guru
          vExpertCommunity WarriorsUser Moderators

          Do you get a meaningfull VM name when you do it like this ?

           

          $SnapshotAge = 10
          $AllSnapShots = Get-View -ViewType virtualmachine -Property Name,snapshot -Filter @{"Snapshot"="VMware.Vim.VirtualMachineSnapshotInfo"} $Snapshots = @() Foreach ($Snap in $AllSnapShots){   $Snapshots += New-Object PSOBject -Property @{     Root = $Snap.snapshot.rootsnapshotlist
             
          Name = $snap.Name
            } } $Aged = $Snapshots | where {$_.Root.CreateTime -lt ((Get-Date).AddDays(-$SnapshotAge))} $NewSnapData = @() Foreach ($Snapshot in $Aged){   $NewDataSet = "" | Select VM, Name, DaysOld, Created, Description
            $NewDataSet.VM = $Snapshot.Name
           
          $NewDataSet.Name = $Snapshot.Root[0].Name
            $NewDataSet.DaysOld = ((Get-Date) - ($Snapshot.Root[0].CreateTime)).Days
            $NewDataSet.Created = $Snapshot.Root[0].CreateTime
            $NewDataSet.Description = $Snapshot.Root[0].Description
            $NewSnapData += $NewDataSet
          }
          $NewSnapData
          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Phantom Snapshot found for a non-existent vm.
            Zsoldier Expert
            vExpert

            Interesting approach.  I wrote my script so long ago.  Yes, I'm able to see the VM name now.  It makes much more sense why the name hasn't been showing up now.  The object in question was a vm template object.

             

            Thanks for the assistance Luc.