VMware Cloud Community
GordonPM
Enthusiast
Enthusiast
Jump to solution

Full procedure to remove iSCSI disks

Following replacement of back end storage, I'm in the process of removing old disk targets from vCenter - (VCSA, 6.7, Nimble Storage)

  • Using the UI, I unmounted the old disks
  • I then used this script to detach the disks from each host

$LunIDs = "eui.bd9d3d41c50c92776c9ce900e10a9042"

$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

example.jpg

PS is as as follows:

$LunIDs = "eui.164448e66d6857396c9ce900538bec87"

$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

example2.jpg


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"?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
2 Replies
GordonPM
Enthusiast
Enthusiast
Jump to solution

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.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos