Hi
can someone help me on this script.
1.while fetching the size of the snapshot again I am issuing command (get-snapshot) that's wrong i am assuming.I already given virtual machine properties (Name,snapshot) while using get-view so how to get size of snap correctly with same get-view.
2. Required user info(Who created snapshot) I am working with get-view taskmanager but failing to fetch user details. Please add the code to get user info with in this script.
$allvcenterservers = 'vcenter1','vcenter2'
$CurrentDate = Get-Date -Format 'MM-dd-yyyy_hh-mm-ss'
$csvFiles = @()
foreach($vcenterserver in $allvcenterservers){
$snapreport = @()
Connect-VIServer -Server $vcenterserver -User admin -Password supersceret |Out-Null
$snapreport+=Get-View -ViewType VirtualMachine -Filter @{"Snapshot"="VMware.Vim.VirtualMachineSnapshotInfo"} -Server $vcenterserver -Property Name,snapshot | % {
$vmname = $_.Name
(Get-View -Id $_.MoRef -Property Snapshot).Snapshot.RootSnapshotList |Select-Object @{N="Vcenterserver";E={$vcenterserver}},
@{N="VM";E={$vmname}},
@{N="SnapshotName";E={$_.Name}},
@{N="SnapshotCreated Date";E={$_.CreateTime}},
@{N="Snap Description";E={$_.Description}},
@{N="Snap Size";E={(Get-Snapshot -Name $_.Name -VM $vmname).SizeGB}}
}
if($snapreport.Count -ne 0){
$filename = "C:\snapreport-on-$($vcenterserver)-$($CurrentDate).csv"
$csvFiles += $filename
$snapreport |Export-Csv -Path $filename -NoTypeInformation -NoClobber -UseCulture
}
}
Send-MailMessage -From "testuser@vmware.com" -To "testuser@vmware.com" -Subject "vms which contains snapshots on $($allvcenterservers)" ` -Body "The attachment contains all the vms which contains snapshots on $($allvcenterservers)" ` -Attachments $csvFiles -SmtpServer 'testsmpt.vmware.com'
To find the user that created a snapshot, you will have to find the Task that created the snapshot.
There is an example in Alan's SnapReminder script.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD. I will Try it.
Can you please correct me on Size of the snapshot
1.while fetching the size of the snapshot again I am issuing command (get-snapshot) that's wrong i am assuming.I already given virtual machine properties (Name,snapshot) while using get-view so how to get size of snap correctly with same get-view.
@{N="Snap Size";E={(Get-Snapshot -Name $_.Name -VM $vmname).SizeGB}}