Removing a bunch of Hosts from Nimble using PowerShell

As i was decommisionning a bunch of hosts i had to remove them from the Access Groups / LUN Mapping in Nimble. Sadly the vCenter plugin does a great job in provisioning new hosts but removing is not implemented

This snip goes ahead, connects to your vCenter, grabs all hosts in a specifc folder and is then removing it from the Nimble config. Feel free to adapt to your needs!

Connect-NSGroup nimble.local.domain
Connect-VIServer vcenter.local.domain

$hosts = Get-Folder "toDelete" | Get-VMHost 

foreach($Server in $hosts)
{
	#Nimble Plugin for vCenter names IGroups with EsxHost-
	$InitiatorGroup = "EsxHost-"+$Server.Name
	Remove-HostFromNimble -InitiatorGroup $InitiatorGroup
}


function Remove-HostFromNimble([string]$InitiatorGroup)
{
	foreach($volume in Get-NSAccessControlRecord -initiator_group_name $InitiatorGroup)
	{
		try
		{
			$volume |  Remove-NSAccessControlRecord -erroraction Continue
			Write-Host "Removed $($volume.vol_name) from $($volume.initiator_group_name)"
		}
		catch
		{
			Write-Host "$($volume.vol_name) no longer found for $($volume.initiator_group_name)"
		}
	}
	Get-NSInitiatorGroup -name $InitiatorGroup | Remove-NSInitiatorGroup
}

Leave a Reply