9 Replies Latest reply on Nov 22, 2017 6:08 AM by ChrZi

    Retrieve snapshots of all VM's

    airinaga Novice

      Has anyone tried this? And or have been successful? Simply trying to retrieve all snapshots of VM's and generate a list.

        • 1. Re: Retrieve snapshots of all VM's
          dhanarajramesh Expert

          you can use simply RVtools to findout the snapshots and snapshot vm. and aslo you can use power cli as below $myVMs = Get-VM $VMsWithSnaps = @() foreach ($vm in $myVMs) {     $vmView = $vm | Get-View     if ($vmView.snapshot -ne $null) {         Write-Host "VM $vm has a snapshot"         $SnapshotEvents = Get-VIEvent -Entity $vm -type info -MaxSamples 1000 | Where {             $_.FullFormattedMessage.contains("Create virtual machine snapshot")}         try {         $user = $SnapshotEvents[0].UserName         $time = $SnapshotEvents[0].CreatedTime         } catch [System.Exception] {             $user = $SnapshotEvents.UserName             $time = $SnapshotEvents.CreatedTime         }         $VMInfo = “” | Select "VM","CreationDate","User"         $VMInfo."VM" = $vm.Name         $VMInfo."CreationDate" = $time         $VMInfo."User" = $user         $VMsWithSnaps += $VMInfo     } } $VMsWithSnaps | Sort CreationDate

          • 2. Re: Retrieve snapshots of all VM's
            airinaga Novice

            Is it possible to send a generic email every time a snapshot is created to a designated email address, specifying the username of who created the snapshot and the VM the snapshot was created on?

             

            Thanks for all the help so far.

            • 3. Re: Retrieve snapshots of all VM's
              Cyberfed27 Hot Shot

              I have a powershell script that emails me daily each VM that has a snapshot and the snapshot name. It integrates with powerCLI.

              I use it to clean up stale/obsolete snapshots other admins forget about.

               

              Get-VM | Select-Object -ExpandProperty Name | Out-File "C:\scripts\VMList.txt"

              Get-Snapshot -VM (Get-Content C:\scripts\VMList.txt) | Select-Object VM,Name | Format-List | Out-file C:\scripts\ssmail.txt

              1 person found this helpful
              • 4. Re: Retrieve snapshots of all VM's
                airinaga Novice

                Awesome! that is exactly what I'm trying to do. Please excuse my inexperience with powerCLI as I am just figuring out how all of this works.

                 

                 

                Is this how you are sending the report to yourself?

                $Report = Get-VM | Sort-Object -Property Name | Out-String

                Send-MailMessage -from $MailSender -to "you@yourdomain.com" -subject "Sending the vSphere report" -body $Report -smtpServer $MailSmtpServer

                 

                 

                 

                Thanks for all the help!

                • 5. Re: Retrieve snapshots of all VM's
                  Cyberfed27 Hot Shot

                  Take the time to learn some basic powershell. PowerCLI is just powershell commands for VMware. Just an added module with a bunch of cmdlets.

                   

                   

                  Send-MailMessage -To "email@domain.com" -From "Noreply@domain.com" -SmtpServer "IP address of email server or DNS name" - Subject "Snapshot Report" -Attachments C:\scripts\ssmail.txt

                  1 person found this helpful
                  • 6. Re: Retrieve snapshots of all VM's
                    warring Enthusiast

                    get-vm | get-snapshot | select name,vm,sizemb

                    • 7. Re: Retrieve snapshots of all VM's
                      Burke- Virtuoso
                      VMware Employees

                      This is the Orchestrator community right? Here, did you see this thread - and package I provided?

                      List all snapshots wth orchestator with

                      • 8. Re: Retrieve snapshots of all VM's
                        airinaga Novice

                        Hey there, Thanks for all the help so far. This is what I have for my snapshot report:

                         

                        $myVMs = Get-VM

                        $VMsWithSnaps = @()

                        foreach ($vm in $myVMs) {

                            $vmView = $vm | Get-View

                            if ($vmView.snapshot -ne $null) {

                                Write-Host "VM $vm has a snapshot"

                                $SnapshotEvents = Get-VIEvent -Entity $vm -type info -MaxSamples 1000 | Where {

                                    $_.FullFormattedMessage.contains("Create virtual machine snapshot")}

                                try {

                                $user = $SnapshotEvents[0].UserName

                                $time = $SnapshotEvents[0].CreatedTime

                                } catch [System.Exception] {

                                    $user = $SnapshotEvents.UserName

                                    $time = $SnapshotEvents.CreatedTime

                                }

                                $VMInfo = “” | Select "VM","CreationDate","User"

                                $VMInfo."VM" = $vm.Name

                                $VMInfo."CreationDate" = $time

                                $VMInfo."User" = $user

                                $VMsWithSnaps += $VMInfo

                        Get-VM | Select-Object -ExpandProperty Name | Out-File "C:\scripts\VMList.txt"

                        Get-Snapshot -VM (Get-Content C:\scripts\VMList.txt) | Select-Object VM,Name,Created,$user | Format-List | Out-file C:\scripts\ssmail.txt

                            }

                        }

                        $VMsWithSnaps | Sort CreationDate

                         

                        *****************************************************

                        This is my ssmail.txt output:

                         

                        VM          : Lab-vCO VM
                        Name        : test
                        Created     : 8/7/2014 2:01:38 PM

                        Adam:

                         

                        VM          : Lab-vCO VM
                        Name        : test1
                        Created     : 8/11/2014 1:18:39 PM

                        Adam:

                         

                        VM          : Lab-vCO VM
                        Name        : test2
                        Created     : 8/12/2014 9:38:36 AM

                        Adam:

                         

                        VM          : Test VM
                        Name        : test
                        Created     : 8/13/2014 9:49:42 AM

                        Adam:

                        ********************************************************

                        It seems that the last person to create a snapshot will have their username populated with every snapshot output. For example: It say's "Adam" created all the snapshots, when this is not true, any suggestions?

                         

                        Thanks.

                        • 9. Re: Retrieve snapshots of all VM's
                          ChrZi Lurker

                          Sorry for pushing up that article again...

                          In the past I was very happy with the Snapshot Reminder from http://virtu-al.net/

                          But now as I need some exclusions in the reminder script, I did find the script of Steve Schofield which also uses the "function GetSnapList"

                           

                          As Backup makes a Snapshot for VBA every day, this function does not display the "REAL" Snapshot creation date (still old snapshot active) and not the Real User.

                          It displays the date of yesterday and the backupuser. Unusable! Any suggestions? Did you find a fix for this issue?