From c39a39d8dfb40739340af9d4561ac0d4b97301f0 Mon Sep 17 00:00:00 2001 From: aaronwsmith Date: Fri, 29 Jul 2016 16:38:46 -0500 Subject: [PATCH 1/3] VM-CdDrive-Report 1.0 PowerActions report script for Cluster objects. Reports on status of all VM's CD-Drives, making it easy to find VMs connected to a given ISO or that might be using a physical ESXI host drive and unable to vMotion. --- PowerActions/VM-CdDrive-Report.ps1 | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 PowerActions/VM-CdDrive-Report.ps1 diff --git a/PowerActions/VM-CdDrive-Report.ps1 b/PowerActions/VM-CdDrive-Report.ps1 new file mode 100644 index 0000000..7fb3fd8 --- /dev/null +++ b/PowerActions/VM-CdDrive-Report.ps1 @@ -0,0 +1,52 @@ +<# +.MYNGC_REPORT +#> + +# AUTHOR: Aaron Smith (@awsmith99) +# VERSION: 1.0 +# PUBLISHED: 2016.07.29 +# ABOUT : PowerActions Report Script that reports on VMs CD-Drive configuration, making it easy +# to find VMs holding onto ISOs that you need to update, or VMs that can't vMotion +# because they are tied into a physical resource from the ESXi host that is running it. +# VM 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. Script is able +# to report on VMs with multiple CD-Drives as well. + +param +( + [Parameter(Mandatory=$true)] + [VMware.VimAutomation.ViCore.Types.V1.Inventory.Cluster] + $vParam +); + +[Array] $vmList = @( Get-VM -Location $vParam | Sort Name ); + +foreach ( $vmItem in $vmList ) +{ + [Array] $vmCdDriveList = @( Get-CDDrive -VM $vmItem ); + + foreach ( $vmCdDriveItem in $vmCdDriveList ) + { + [String] $insertedElement = ""; + [String] $connectionType = ""; + + switch ( $vmCdDriveItem ) + { + { $_.IsoPath } { $insertedElement = $_.IsoPath; $connectionType = "ISO"; break; } + { $_.HostDevice } { $insertedElement = $_.HostDevice; $connectionType = "Host Device"; break; } + { $_.RemoteDevice } { $insertedElement = $_.RemoteDevice; $connectionType = "Remote Device"; break; } + default { $insertedElement = "None"; $connectionType = "Client Device"; break; } + } + + $output = New-Object -TypeName PSObject; + + $output | Add-Member -MemberType NoteProperty -Name "VM" -Value $vmItem + $output | Add-Member -MemberType NoteProperty -Name "CD-Drive" -Value $vmCdDriveItem.Name; + $output | Add-Member -MemberType NoteProperty -Name "Connection" -Value $connectionType; + $output | Add-Member -MemberType NoteProperty -Name "Inserted" -Value $insertedElement; + $output | Add-Member -MemberType NoteProperty -Name "Connected" -Value $vmCdDriveItem.ConnectionState.Connected; + $output | Add-Member -MemberType NoteProperty -Name "StartConnected" -Value $vmCdDriveItem.ConnectionState.StartConnected; + $output | Add-Member -MemberType NoteProperty -Name "AllowGuestControl" -Value $vmCdDriveItem.ConnectionState.AllowGuestControl; + $output; + } +} \ No newline at end of file From 3cf6bf5d973d4794ac327b2554a2319ac522b17a Mon Sep 17 00:00:00 2001 From: aaronwsmith Date: Wed, 3 Aug 2016 14:29:19 -0500 Subject: [PATCH 2/3] VM-CdDrive-Report.ps1 -- Minor revision to metadata to confirm to PowerActions standards. Added .LABEL and .DESCRIPTION fields in place of the custom comments that documented the script. Tried to specify KEY(VM) under .MYNGC_REPORT section but that triggered validation errors for me in PowerActions. --- PowerActions/VM-CdDrive-Report.ps1 | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/PowerActions/VM-CdDrive-Report.ps1 b/PowerActions/VM-CdDrive-Report.ps1 index 7fb3fd8..5778bc3 100644 --- a/PowerActions/VM-CdDrive-Report.ps1 +++ b/PowerActions/VM-CdDrive-Report.ps1 @@ -1,17 +1,15 @@ <# .MYNGC_REPORT +.LABEL +VM CD-Drive Report +.DESCRIPTION +PowerActions Report Script that reports on VMs CD-Drive configuration, making it easy to find VMs holding onto ISOs that you +need to update, or VMs that can't vMotion because they are tied into a physical resource from the ESXi host that is running it. +VM 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. Script is able to report on VMs with multiple CD-Drives as well. Version 1.0, written by +Aaron Smith (@awsmith99), published 07/29/2016. #> -# AUTHOR: Aaron Smith (@awsmith99) -# VERSION: 1.0 -# PUBLISHED: 2016.07.29 -# ABOUT : PowerActions Report Script that reports on VMs CD-Drive configuration, making it easy -# to find VMs holding onto ISOs that you need to update, or VMs that can't vMotion -# because they are tied into a physical resource from the ESXi host that is running it. -# VM 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. Script is able -# to report on VMs with multiple CD-Drives as well. - param ( [Parameter(Mandatory=$true)] From 002bf2b97ade522a7161b58a7a905280c4e3d5f2 Mon Sep 17 00:00:00 2001 From: aaronwsmith Date: Wed, 3 Aug 2016 15:08:05 -0500 Subject: [PATCH 3/3] VM-CdDrive-Report.ps1 - Final revision to metadata Figured out you have to explicitly escape the () characters when editing a PowerActions script within the Web Client. Added in KEY(VM) to tell PowerActions which column to use for Context Menu support within Web Client. Also seemed to speed up execution of the script! --- PowerActions/VM-CdDrive-Report.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/PowerActions/VM-CdDrive-Report.ps1 b/PowerActions/VM-CdDrive-Report.ps1 index 5778bc3..584484d 100644 --- a/PowerActions/VM-CdDrive-Report.ps1 +++ b/PowerActions/VM-CdDrive-Report.ps1 @@ -1,5 +1,6 @@ <# .MYNGC_REPORT +KEY\(VM\) .LABEL VM CD-Drive Report .DESCRIPTION