Reply to Message

View discussion in a popup

Replying to:
airinaga
Contributor
Contributor

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.

Reply
0 Kudos