A PowerCLI function to remove Vibs installed on a VMware host.
Expects a VMHost object, and a list og vib names.
You must use the -Remove switch to actually remove vibs, otherwise it will just list the installed vibs matching the provided list of vib names.
If you add the -Restart switch the VMware host will be restarted after removing the vibs
function Remove-Vib
{
[CmdletBinding(SupportsShouldProcess=$True)]
Param(
[Parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true)]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl[]]
$VMHosts,
[Parameter(Mandatory=$true,Position=1)]
[string[]]
$VibNames,
[switch]
$Remove=$false,
[switch]
$Restart=$false
)
Begin {}
Process {
foreach ($VMHost in $VMHosts) {
# Write-Output "Searching for vibs on VMHost: $($VMHost.Name)"
$esxcli = $VMHost | Get-EsxCli
$vibs = $esxcli.software.vib.list() | Where { $VibNames -contains $_.Name }
if ($vibs) {
# Write-Output "Vibs found:"
$vibs | Select @{l='VMHost';e={$VMHost.Name}}, Name, ReleaseDate, Version
if ($Remove -eq $true) {
foreach ($vib in $vibs) {
Write-Output "Removing vib: $($vib.Name)"
$esxcli.software.vib.remove($null, $true, $false, $true, $vib.Name)
}
if ($Restart -eq $true) {
Write-Output "Restarting VMHost: $($VMHost.Name)"
Restart-VMHost -VMHost $VMHost -Confirm:$false
}
}
}
else {
Write-Output "$($VMHost.Name): No vibs found"
}
}
}
End {}
}