Has anyone tried this? And or have been successful? Simply trying to retrieve all snapshots of VM's and generate a list.
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
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
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.
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
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!
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
get-vm | get-snapshot | select name,vm,sizemb
This is the Orchestrator community right? Here, did you see this thread - and package I provided?
List all snapshots wth orchestator with
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.
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?
I get the following error when I run the command from powershell:
virtualMwsnapshots.ps1:1 char:50
+ $myVMs = Get-VM $VMsWithSnaps = @() foreach ($vm in $myVMs) { $vm ...
+ ~~
Unexpected token 'in' in expression or statement.
At C:\users\*******\desktop\virtualMwsnapshots.ps1:1 char:49
+ $myVMs = Get-VM $VMsWithSnaps = @() foreach ($vm in $myVMs) { $vm ...
+ ~
Missing closing ')' in expression.
At C:\users\********\desktop\virtualMwsnapshots.ps1:1 char:59
+ $myVMs = Get-VM $VMsWithSnaps = @() foreach ($vm in $myVMs) { $vm ...
+ ~
Unexpected token ')' in expression or statement.
At C:\users\*******\desktop\virtualMwsnapshots.ps1:1 char:408
+ ... y { $user = $SnapshotEvents[0].UserName $time = $Snap ...
+ ~~~~~
Unexpected token '$time' in expression or statement.
At C:\users\*******\desktop\virtualMwsnapshots.ps1:1 char:541
+ ... $user = $SnapshotEvents.UserName $time = $Snap ...
+ ~~~~~
Unexpected token '$time' in expression or statement.
At C:\users\******\desktop\virtualMwsnapshots.ps1:1 char:791
+ ... $user $VMsWithSnaps += $VMInfo } } $VMsWithSnaps | Sort ...
+ ~~~~~~~~~~~~~
Unexpected token '$VMsWithSnaps' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken