Managing vCenter Plugins with PowerCLI
VMUG, vBeers, vLunch….whatever the occasion, there are always some great conversations and I particularly enjoy finding out what other people are up to in their environments. During vLunch last week, I was talking with Ed Grigson and he asked whether it was possible to use PowerCLI to remove vCenter Plugins that have got into an orphaned state, i.e. the uninstall process did not remove the vCenter plugin. VMware KB article 1025360 details a process whereby you can clean these up by navigating to the vCenter Server with a web browser. Point 3) mentions ExtensionManager and that got me thinking that it should be possible to do this via PowerCLI.
Coincidently I have seen a few people tweeting about this topic in the last week, so thought it might be useful to make some PowerCLI functions for managing this process.
First up is Get-vCenterPlugin , this function will return either all vCenter Plugins or a specifc one, e.g:
Get-vCenterPlugin
or
Get-vCenterPlugin -Name 'vCenter Hardware Status'
(Note: the object doesn’t actually have a Name property, but what is stored in Description appears in most cases to be the name)
function Get-vCenterPlugin {
<# .SYNOPSIS Retrieves vCenter Plugins
.DESCRIPTION Retrieves vCenter Plugins
.PARAMETER Name Name of the Plugin to return
.EXAMPLE PS C:\\> Get-vCenterPlugin -Name 'vCenter Hardware Status'
.NOTES Author: Jonathan Medd Date: 17/02/2012 #>
\[CmdletBinding()\] param( \[Parameter(Position=0,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)\] \[System.String\] $Name )
begin { $ExtensionManager = Get-View ExtensionManager }
process {
if ($Name){ $ExtensionManager.ExtensionList | Select-Object @{Name='Description';Expression={$\_.Description.Label}},Key,Company,Version | Where-Object {$\_.Description -eq $Name} }
else { $ExtensionManager.ExtensionList | Select-Object @{Name='Description';Expression={$\_.Description.Label}},Key,Company,Version | Sort-Object Description }
} }
If you have a vCenter plugin in an orphaned state then it may look something like this:
To remove the vCenter plugin we need to supply the plugin Key to the UnregisterExtension method. The Remove-vCenterPlugin function has two parameters, Name and Key. If you supply the name of the plugin then the function first of all determines the key and subsequently supplies it to the UnregisterExtension method.
Remove-vCenterPlugin "vCenter Operations Standard"
The vCenter Operations Standard plugin has been removed.
function Remove-vCenterPlugin {
<# .SYNOPSIS Removes vCenter Plugins
.DESCRIPTION Removes vCenter Plugins
.PARAMETER Name Name of the Plugin to remove
.EXAMPLE PS C:\\> Remove-vCenterPlugin -Name '3PAR\_Plug-In'
.EXAMPLE PS C:\\> Remove-vCenterPlugin -Key 'com.3par.3PAR\_Plug-In'
.EXAMPLE PS C:\\> Get-vCenterPlugin -Name '3PAR\_Plug-In' | Remove-vCenterPlugin
.NOTES Author: Jonathan Medd Date: 17/02/2012 #>
\[CmdletBinding(DefaultParametersetName="Name")\] param( \[Parameter(ParameterSetName="Name",Position=0,Mandatory=$true,HelpMessage="Name of plugin to remove", ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)\] \[Alias('Description')\] \[System.String\] $Name,
\[Parameter(ParameterSetName="Key",Position=0,Mandatory=$true,HelpMessage="Key of plugin to remove", ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)\] \[System.String\] $Key )
begin { $ExtensionManager = Get-View ExtensionManager }
process {
switch ($PsCmdlet.ParameterSetName) {
"Name" { $KeyID = ($ExtensionManager.ExtensionList | Select-Object @{Name='Description';Expression={$\_.Description.Label}},Key,Company,Version | Where-Object {$\_.Description -eq $Name}).Key $ExtensionManager.UnregisterExtension("$KeyID") }
"Key" { $ExtensionManager.UnregisterExtension("$Key") }
} } }
The sharp eyed amongst you will of course notice that the first plugin in the list does not have the Description property populated, so to remove the vShield Manager Plugin you will need to supply the key; which you can determine by first running Get-vCenterPlugin.
Remove-vCenterPlugin -Key com.vmware.vShieldManager
Remove-vCenterPlugin also accepts pipeline input, so if you have a list of plugins to remove you can automate this a bit smarter than one at a time, e.g.:
'vCenter Operations Standard','3PAR\_Plug-In' | Get-vCenterPlugin | Remove-vCenterPlugin
or:
Get-Content plugins.txt | Get-vCenterPlugin | Remove-vCenterPlugin
All being well your vCenter Plugins should now look tidy again.
Big thanks to Ed for helping me test this out. You should check out his blog, he has made some great posts recently in addition to his well known VCAP study guide.