VM-Snapshot-Report.ps1

Ready for merge if approved ... added date created and calculated age in
days for the snapshot as additional columns in the report.
This commit is contained in:
aaronwsmith
2016-08-10 15:06:27 -05:00
parent 48c4839be3
commit 067de29b30

View File

@@ -4,10 +4,10 @@ KEY\(VM\)
.LABEL .LABEL
VM Snapshot Report VM Snapshot Report
.DESCRIPTION .DESCRIPTION
PowerActions Report Script that reports on VMs with snapshots along with their description, size of the snapshot in GB, the VM's provisioned vs. used space in GB, PowerActions Report Script that reports on VMs with snapshots along with their description, date of the snapshot, age in days of the snapshot, size of the snapshot in GB,
if the snapshot is the current one being used, its parent snapshot (if there is one), and the Power state of the VM itself. VM object is key (as it's the first the VM's provisioned vs. used space in GB, if the snapshot is the current one being used, its parent snapshot (if there is one), and the Power state of the VM itself. VM
managed object in the output), enabling you the ability to right-click an entry in the report to edit the target VM. Version 1.0, written by Aaron Smith (@awsmith99), object is key (as it's the first managed object in the output), enabling you the ability to right-click an entry in the report to edit the target VM. Version 1.0, written
published 08/10/2016. by Aaron Smith (@awsmith99), published 08/10/2016.
#> #>
param param
@@ -28,12 +28,15 @@ foreach ( $vmItem in $vmList )
$vmProvisionedSpaceGB = [Math]::Round( $vmItem.ProvisionedSpaceGB, 2 ); $vmProvisionedSpaceGB = [Math]::Round( $vmItem.ProvisionedSpaceGB, 2 );
$vmUsedSpaceGB = [Math]::Round( $vmItem.UsedSpaceGB, 2 ); $vmUsedSpaceGB = [Math]::Round( $vmItem.UsedSpaceGB, 2 );
$snapshotSizeGB = [Math]::Round( $snapshotItem.SizeGB, 2 ); $snapshotSizeGB = [Math]::Round( $snapshotItem.SizeGB, 2 );
$snapshotAgeDays = ((Get-Date) - $snapshotItem.Created).Days;
$output = New-Object -TypeName PSObject; $output = New-Object -TypeName PSObject;
$output | Add-Member -MemberType NoteProperty -Name "VM" -Value $vmItem; $output | Add-Member -MemberType NoteProperty -Name "VM" -Value $vmItem;
$output | Add-Member -MemberType NoteProperty -Name "Name" -Value $snapshotItem.Name; $output | Add-Member -MemberType NoteProperty -Name "Name" -Value $snapshotItem.Name;
$output | Add-Member -MemberType NoteProperty -Name "Description" -Value $snapshotItem.Description; $output | Add-Member -MemberType NoteProperty -Name "Description" -Value $snapshotItem.Description;
$output | Add-Member -MemberType NoteProperty -Name "Created" -Value $snapshotItem.Created;
$output | Add-Member -MemberType NoteProperty -Name "AgeDays" -Value $snapshotAgeDays;
$output | Add-Member -MemberType NoteProperty -Name "ParentSnapshot" -Value $snapshotItem.ParentSnapshot.Name; $output | Add-Member -MemberType NoteProperty -Name "ParentSnapshot" -Value $snapshotItem.ParentSnapshot.Name;
$output | Add-Member -MemberType NoteProperty -Name "IsCurrentSnapshot" -Value $snapshotItem.IsCurrent; $output | Add-Member -MemberType NoteProperty -Name "IsCurrentSnapshot" -Value $snapshotItem.IsCurrent;
$output | Add-Member -MemberType NoteProperty -Name "SnapshotSizeGB" -Value $snapshotSizeGB; $output | Add-Member -MemberType NoteProperty -Name "SnapshotSizeGB" -Value $snapshotSizeGB;