Following replacement of back end storage, I'm in the process of removing old disk targets from vCenter - (VCSA, 6.7, Nimble Storage)
$Clustername = "AMD"
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
}
}
All good so far
I'm now trying to remove the disks from each host availability list
PS is as as follows:
$Clustername = "AMD"
Function Remove-Lun {
Param(
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl]$VMHost,
[string]$CanonicalName
)
$esxcli = Get-EsxCli -VMHost $VMHost -v2
$esxcli.storage.core.device.detached.list.Invoke() | Where-Object { $_.DeviceUID -eq $CanonicalName } | ForEach-Object {
$detach = @{ device = $_.DeviceUID }
$esxcli.storage.core.device.detached.remove.Invoke($detach)
}
}
$ClusterHosts = Get-Cluster $Clustername | Get-VMHost
Foreach($VMHost in $ClusterHosts) {
Foreach($LunID in $LunIDs) {
Write-Host "Removing" $LunID "from" $VMHost -ForegroundColor "Yellow"
Remove-Lun -VMHost $VMHost -CanonicalName $LunID
}
}
However, if I run this everything seems fine, but if I then mark the volume "OFFLINE" in the storage and refresh the GUI, the LUN is still in this list.
Additionally, I have some LUNs which are set offline in storage and show as "Dead or Error" in the GUI
Running the above script results in this error:
[quote]
Message: EsxCLI.CLIFault.summary;
InnerText: Unable to remove detached device entry eui.164448e66d6857396c9ce900538bec87Error was: Unable to change device state, the
device is in an incorrect state.: Sysinfo error: Not supportedSee VMkernel log for details.EsxCLI.CLIFault.summary
[/quote]
I guess I have two quesitons here:
Do I need to physically delete the volume from the storage rather than just set offline?
What's the sequence/procedure via PowerCLI to remove entries from the storage device list properly/fully, even if showing "Dead or Error"?
A rescan should remove dead LUNs (he RescanVmfs switch is probably not required in our case).
Get-VMHost | Get-VMHostStorage -Refresh -RescanAllHba -RescanVmfs
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I answered my first question - I deleted the volume and it was still in the device list, but showing dead or error. I ran the script again and then refeshed devices and even though the volume no longer exists, it's showing as "Detached". I'm now very confused.
A rescan should remove dead LUNs (he RescanVmfs switch is probably not required in our case).
Get-VMHost | Get-VMHostStorage -Refresh -RescanAllHba -RescanVmfs
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference