I found this small and straight forward handy little script by David Stamen (davidstamen.com)
https://davidstamen.com/2015/09/14/using-powercli-to-detach-luns/
# PowerCLI Script for detaching luns from a cluster
# @davidstamen
$LunIDs = "naa.6000000001","naa.600000002"
$Clustername = "MyCluster"
function Detach-Disk {
param(
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl]$VMHost,
[string]$CanonicalName )
$storSys = Get-View $VMHost.Extensiondata.ConfigManager.StorageSystem
$lunUuid = (Get-ScsiLun -VmHost $VMHost | where {$_.CanonicalName -eq $CanonicalName}).ExtensionData.Uuid
$storSys.DetachScsiLun($lunUuid)
}
$ClusterHosts = Get-Cluster $Clustername | Get-VMHost
Foreach($VMHost in $ClusterHosts)
{
Foreach($LUNid in $LunIDs)
{
Write-Host "Detaching" $LUNid "from" $VMHost -ForegroundColor "Yellow"
Detach-Disk -VMHost $VMHost -CanonicalName $LUNid
}
}
This almost does it for me, I still need to connect to every host involved and removed the detached LUNs
Procedure being first SSH to host and then running the CLI commands:
esxcli storage core device detached list
esxcli storage core device detached remove -d naa.6000000001
esxcli storage core device detached remove -d naa.6000000002
and so on.
I cant help to think they ought to be a way to add this to David's existing script. Utilizing the $LunIDs and $VMHost that have already been defined.
All i seem to be finding are standalone scripts and would appear to be way more convoluted than they need to be.
Any suggestions or pointers?