function Get-SnapChild
{
param(
[VMware.Vim.VirtualMachineSnapshotTree]$Snapshot
)
process
{
$snapshot | Select Name, Description, CreateTime
if ($Snapshot.ChildSnapshotList.Count -gt 0)
{
$Snapshot.ChildSnapshotList | % {
Get-SnapChild -Snapshot $_
}
}
}
}
foreach ($vm in Get-View -ViewType VirtualMachine -Property Name, Snapshot -Filter @{'Snapshot' = '' })
{
$vm.Snapshot.RootSnapshotList | % {
Get-SnapChild -Snapshot $_ |
Select @{N = 'VM'; E = { $vm.name } },
@{N = 'Snapshot'; E = { $_.Name } },
@{N = 'Description'; E = { $_.Description } },
@{N = 'CReated'; E = { $_.CreateTime } }
}
}
Get-View -ViewType VirtualMachine -Filter @{'Runtime.PowerState'='poweredOn'} |
Select Name,
@{N='HostName';E={$_.Guest.HostName}},
@{N='Datacenter';E={
$parent = Get-View -Id $_.Parent -Property Name,Parent
while($parent -isnot [VMware.Vim.Datacenter] -and $parent){
$parent = Get-View -Id $parent.Parent -Property Name,Parent
}
if($parent){
$parent.Name
}}},
@{N='Cluster';E={
$parent = Get-View -Id $_.ResourcePool
while($parent -isnot [VMware.Vim.ClusterComputeResource] -and $parent){
$parent = Get-View -Id $parent.Parent -Property Name,Parent
}
if($parent){
$parent.Name}}},
@{N = 'VMHost'; E = {(Get-View -Id $_.Runtime.Host).Name}},
@{N='OS';E={$_.Config.GuestFullName}},
@{N='Boottime';E={$_.Runtime.BootTime}},
@{N='VMState';E={$_.summary.runtime.powerState}},
@{N='IPAddress';E={$_.Guest.ipAddress}},
@{N='MacAddress';E={($_.Config.Hardware.Device | where{$_ -is [VMware.Vim.VirtualEthernetCard]}).MacAddress -join '|'}},
@{N='Portgroup';E={Get-View -Id $vm.Network -Property Name | select -ExpandProperty Name}},
@{N='Memory Total in GB';E={$_.summary.config.memorysizemb.ToString('N0')}},
@{N='DataStore';E={$_.Config.DatastoreUrl[0].Name}},
@{N='Provisioned Space in GB';E={[math]::Round(($vm.Summary.Storage.Committed + $vm.Summary.Storage.UnCommitted)/1GB,2).ToString('N0')}},
@{N='TimeSync';E={$_.Config.Tools.SyncTimeWithHost}},
@{N='ToolsStatus';E={$_.guest.toolsstatus}},
@{N='ToolsVersion';E={$_.config.tools.toolsversion}},
@{N='HardwareVersion';E={$_.config.Version}},
@{N='Site Recovery Manager Group';E={(Get-TagAssignment -Category "SRM Protection Group" -Entity (Get-VIObjectByVIView -VIView $_)).Tag.Name}},
@{n="Networker Policy"; e={$viewThisVM = $_; ($viewThisVM.CustomValue | ?{$_.Key -eq ($viewThisVM.AvailableField | ?{$_.Name -eq "Last EMC vProxy Backup"}).Key}).Value}},
@{N='SnapShot';E={($_.ChildSnapshotList.Name | where{$_ -is [VMware.Vim.VirtualMachineSnapshotTree]})}},
@{N='SnapShot Created';E={($_.ChildSnapshotList.Date | where{$_ -is [VMware.Vim.VirtualMachineSnapshotTree]})}},
@{N='SnapShot Size';E={($_.ChildSnapshotList.Size | where{$_ -is [VMware.Vim.VirtualMachineSnapshotTree]})}}, |
Out-GridView
The Snapshot groups are coming out blank, any help is appreciated.
This should do the trick, except for the Snapshot Size.
Not sure what you want to see there? The size of the delta files linked to that specific snapshot?
Select Name,
@{N='HostName';E={$_.Guest.HostName}},
@{N='Datacenter';E={
$parent = Get-View -Id $_.Parent -Property Name,Parent
while($parent -isnot [VMware.Vim.Datacenter] -and $parent){
$parent = Get-View -Id $parent.Parent -Property Name,Parent
}
if($parent){
$parent.Name
}}},
@{N='Cluster';E={
$parent = Get-View -Id $_.ResourcePool
while($parent -isnot [VMware.Vim.ClusterComputeResource] -and $parent){
$parent = Get-View -Id $parent.Parent -Property Name,Parent
}
if($parent){
$parent.Name}}},
@{N = 'VMHost'; E = {(Get-View -Id $_.Runtime.Host).Name}},
@{N='OS';E={$_.Config.GuestFullName}},
@{N='Boottime';E={$_.Runtime.BootTime}},
@{N='VMState';E={$_.summary.runtime.powerState}},
@{N='IPAddress';E={$_.Guest.ipAddress}},
@{N='MacAddress';E={($_.Config.Hardware.Device | where{$_ -is [VMware.Vim.VirtualEthernetCard]}).MacAddress -join '|'}},
@{N='Portgroup';E={Get-View -Id $vm.Network -Property Name | select -ExpandProperty Name}},
@{N='Memory Total in GB';E={$_.summary.config.memorysizemb.ToString('N0')}},
@{N='DataStore';E={$_.Config.DatastoreUrl[0].Name}},
@{N='Provisioned Space in GB';E={[math]::Round(($vm.Summary.Storage.Committed + $vm.Summary.Storage.UnCommitted)/1GB,2).ToString('N0')}},
@{N='TimeSync';E={$_.Config.Tools.SyncTimeWithHost}},
@{N='ToolsStatus';E={$_.guest.toolsstatus}},
@{N='ToolsVersion';E={$_.config.tools.toolsversion}},
@{N='HardwareVersion';E={$_.config.Version}},
@{N='Site Recovery Manager Group';E={(Get-TagAssignment -Category "SRM Protection Group" -Entity (Get-VIObjectByVIView -VIView $_)).Tag.Name}},
@{n="Networker Policy"; e={$viewThisVM = $_; ($viewThisVM.CustomValue | ?{$_.Key -eq ($viewThisVM.AvailableField | ?{$_.Name -eq "Last EMC vProxy Backup"}).Key}).Value}},
@{N='SnapShot';E={
function Get-Snap{
param([PSObject]$snap)
$snap
if($snap.ChildSnapshotList){
$snap.ChildSnapshotList | %{
Get-Snap -Snap $_
}
}
}
$script:snaps = $_.Snapshot.RootSnapshotList | %{
Get-Snap -Snap $_
}
($script:snaps | sort-Object -property Name).Name -join '|'}},
@{N='SnapShot Created';E={($script:snaps | sort-Object -property Name).CreateTime -join '|'}},
@{N='SnapShot Size';E={}} |
Out-GridView
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not sure what and how you want to include snapshots in that report.
If a VM has more than 1 snapshot, how would you display that in the report?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
In another script that I have for snapshots I run the following:
foreach($vm in Get-View -ViewType Virtualmachine){
$vms = "" | Select-Object VMName, SnapshotName, SnapshotDate, SnapshotSizeGB
$vms.VMName = $vm.Name
$vms.SnapshotName = &{$script:snaps = Get-Snapshot -VM $vm.Name; $script:snaps.Name -join ','}
$vms.SnapshotDate = $script:snaps.Created -join ','
$vms.SnapshotSizeGB = $script:snaps.SizeGB -join ','
$Report += $vms
}
$report | Out-GridView
I return the following
SnapshotName | SnapshotDate | SnapshotSizeGB |
VM Snapshot 4-22-2019, 7:20:23 AM | 4/22/2019 7:20 | 782.0039367 |
I get that, but how would this cover when a VM has more than 1 snapshot?
Or does that never happen in your environment?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ideally the return would be a comma separated entry in the table. We try to maintain our snapshots fairly well and this report is going to assist in that endeavor.
This should do the trick, except for the Snapshot Size.
Not sure what you want to see there? The size of the delta files linked to that specific snapshot?
Select Name,
@{N='HostName';E={$_.Guest.HostName}},
@{N='Datacenter';E={
$parent = Get-View -Id $_.Parent -Property Name,Parent
while($parent -isnot [VMware.Vim.Datacenter] -and $parent){
$parent = Get-View -Id $parent.Parent -Property Name,Parent
}
if($parent){
$parent.Name
}}},
@{N='Cluster';E={
$parent = Get-View -Id $_.ResourcePool
while($parent -isnot [VMware.Vim.ClusterComputeResource] -and $parent){
$parent = Get-View -Id $parent.Parent -Property Name,Parent
}
if($parent){
$parent.Name}}},
@{N = 'VMHost'; E = {(Get-View -Id $_.Runtime.Host).Name}},
@{N='OS';E={$_.Config.GuestFullName}},
@{N='Boottime';E={$_.Runtime.BootTime}},
@{N='VMState';E={$_.summary.runtime.powerState}},
@{N='IPAddress';E={$_.Guest.ipAddress}},
@{N='MacAddress';E={($_.Config.Hardware.Device | where{$_ -is [VMware.Vim.VirtualEthernetCard]}).MacAddress -join '|'}},
@{N='Portgroup';E={Get-View -Id $vm.Network -Property Name | select -ExpandProperty Name}},
@{N='Memory Total in GB';E={$_.summary.config.memorysizemb.ToString('N0')}},
@{N='DataStore';E={$_.Config.DatastoreUrl[0].Name}},
@{N='Provisioned Space in GB';E={[math]::Round(($vm.Summary.Storage.Committed + $vm.Summary.Storage.UnCommitted)/1GB,2).ToString('N0')}},
@{N='TimeSync';E={$_.Config.Tools.SyncTimeWithHost}},
@{N='ToolsStatus';E={$_.guest.toolsstatus}},
@{N='ToolsVersion';E={$_.config.tools.toolsversion}},
@{N='HardwareVersion';E={$_.config.Version}},
@{N='Site Recovery Manager Group';E={(Get-TagAssignment -Category "SRM Protection Group" -Entity (Get-VIObjectByVIView -VIView $_)).Tag.Name}},
@{n="Networker Policy"; e={$viewThisVM = $_; ($viewThisVM.CustomValue | ?{$_.Key -eq ($viewThisVM.AvailableField | ?{$_.Name -eq "Last EMC vProxy Backup"}).Key}).Value}},
@{N='SnapShot';E={
function Get-Snap{
param([PSObject]$snap)
$snap
if($snap.ChildSnapshotList){
$snap.ChildSnapshotList | %{
Get-Snap -Snap $_
}
}
}
$script:snaps = $_.Snapshot.RootSnapshotList | %{
Get-Snap -Snap $_
}
($script:snaps | sort-Object -property Name).Name -join '|'}},
@{N='SnapShot Created';E={($script:snaps | sort-Object -property Name).CreateTime -join '|'}},
@{N='SnapShot Size';E={}} |
Out-GridView
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So the snapshot date is now appearing but no name or size.
The size I know (see my earlier question).
The name was a copy/paste error. I corrected the code above.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So I have been playing around with Measure-Object -Sum function in case there are multiple snapshots:
Get-View -ViewType VirtualMachine -Filter @{'Runtime.PowerState'='poweredOn'} |
Select Name,
@{N='SnapShot Size';E={($script:snaps | Measure-Object -Sum SizeGB).Sum}} but not working.
I realized my mistake in that it requires the following:
Get-VM | Format-Table Name, @{Label="NumSnapshots";Expression={(Get-Snapshot -VM $_ | Measure-Object).Count}}, @{Label="TotalSnapShotSizeMB";Expression={(Get-Snapshot -VM $_ | Measure-Object -Sum SizeMB).Sum}}
I am not sure what function I would use to convert that into usable and displayable information per vm. Any suggestions?