VMware Cloud Community
sennaf2
Enthusiast
Enthusiast
Jump to solution

Check if DataStore is detached from host

I have migrated all my VMs to new VMFS6 datastores after upgrading vCenter.  I have placed all the VMFS5 datastores in maintenace mode and unmounted all.  The last thing I need to do is detach each from all the hosts.  I found a script to detach the LUN from the hosts, but I want something to show me hosts still attached if the detach script missed one.

I have tried to find where this value is but I can not find it. 

Here is what I have tried

$esx = Get-VMHost -Name 'esxi01.MyDomain.com'

$storSys = Get-view $esx.ExtensionData.ConfigManager.StorageSystem

$storSys.StorageDeviceInfo.ScsiLun | where {$_.CanonicalName -eq 'naa.xxxxxxxxxxxxxxxxxxxxxxxxxxx'}

--and--

$ScsiLun = Get-ScsiLun -VmHost $esx -LunType disk | Where-Object {$_.CanonicalName -eq 'naa.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}

But I can not find where this property is.

Thanks in advance for any help.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

One way to check is with esxcli.

See if the device appears in the list of detached LUNs

$esxName = 'MyEsx'

$esx = Get-VMHost -Name $esxName


$esxcli = Get-EsxCli -VMHost $esx -V2

$esxcli.storage.core.device.detached.list.Invoke()


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
10 Replies
daphnissov
Immortal
Immortal
Jump to solution

Wrong sub-forum. Move to PowerCLI.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

One way to check is with esxcli.

See if the device appears in the list of detached LUNs

$esxName = 'MyEsx'

$esx = Get-VMHost -Name $esxName


$esxcli = Get-EsxCli -VMHost $esx -V2

$esxcli.storage.core.device.detached.list.Invoke()


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
sennaf2
Enthusiast
Enthusiast
Jump to solution

LucD Thanks for the help.  My scrip is working but for some reason it is not clearing the old LUNs after I remove them from the storage array and rescan storage in vmware?

I have also modified it slightly to search all hosts.

Here is my modified script.

Clear-Variable -name esx

Clear-Variable -name esxhosts

Clear-Variable -name esxcli

#$esxName = 'MyEsx'

$esxhosts = Get-VMHost

Foreach ($esx in $esxhosts){

$esxcli = Get-EsxCli -VMHost $esx.Name -V2

Write-Host $esx.Name

$esxcli.storage.core.device.detached.list.Invoke()

}

But the output is this

PS C:\EQR\Detach Datastore> C:\EQR\Detach Datastore\checkdetachAllHosts.ps1

esxhost9.mydomain.com

esxhost15.mydomain.com

esxhost3.mydomain.com

DeviceUID                            State

---------                            -----

naa.60000970000197901057533030303243 off 

naa.60000970000197901057533030303336 off 

naa.60000970000197901057533030303243 off 

naa.60000970000197901057533030303336 off 

naa.60000970000197901057533030303243 off 

naa.60000970000197901057533030303336 off 

esxhost4.mydomain.com

naa.60000970000197901057533030303243 off 

naa.60000970000197901057533030303336 off 

esxhost1.mydomain.com

naa.60000970000197901057533030303243 off 

naa.60000970000197901057533030303336 off 

esxhost7.mydomain.com

naa.60000970000197901057533030303243 off 

I have completely remove naa.60000970000197901057533030303243 from vSphere and Storage.  The UUID is not present in the vSphere webclient 6.7 but displays in this script?

Vince Rucolas

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you rescan storage and HBA?
From the Web Client or through an esxcli command?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
sennaf2
Enthusiast
Enthusiast
Jump to solution

I did not think it made a difference.  I originally scanned from the 6.7 WebClient.  When I saw this thread I ran it from PowerCLI and have the same results.

Here is the command I ran.  Thanks to Andreas Lesslhumer on https://www.running-system.com/

Get-Cluster ‘name_of_your_cluster‘ | Get-VMHost | Get-VMHostStorage -RescanAllHba -RescanVmfs

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you try like this?

$esxcli.storage.core.adapter.rescan.Invoke(@{all=$true})


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
sennaf2
Enthusiast
Enthusiast
Jump to solution

I added it to the script as the first command after ForEach and it still shows them all.

Clear-Variable -name esx

Clear-Variable -name esxhosts

Clear-Variable -name esxcli

$esxhosts = Get-VMHost

Foreach ($esx in $esxhosts){

$esxcli.storage.core.adapter.rescan.Invoke(@{all=$true})

$esxcli = Get-EsxCli -VMHost $esx.Name -V2

Write-Host $esx.Name

$esxcli.storage.core.device.detached.list.Invoke()

}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That line should go after the Get-EsxCli line.

Could you also check if you see that LUN as a greyed-out entry in the Web Client after the detach?

That entry should disappear after a rescan of the HBA


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
sennaf2
Enthusiast
Enthusiast
Jump to solution

I moved the line to below the Get-EsxCli, ran the script and received the same result.

I logged into the web client the device was there and grayed out and showed detached.

I scanned the storage from the Web Client and it still appears in Storage Devices.

Once I remove the device from the storage array it disappears in the gui but not the script.

Thanks for all your help with this. 

It is working but when I run the script there are more and more entries which makes it harder to distinguish what is detached.

PS C:\EQR\Detach Datastore> C:\EQR\Detach Datastore\checkdetachAllHosts.ps1

true

eqresxi09.mydomain.com

DeviceUID                            State

---------                            -----

naa.60000970000196800291533030303231 off 

naa.60000970000196800291533030303236 off 

naa.60000970000196800291533030303241 off 

naa.60000970000196800291533030303242 off 

naa.60000970000196800291533030303434 off 

naa.60000970000196800291533030303435 off 

naa.60000970000196800291533030303537 off 

naa.60000970000196800291533030303832 off 

naa.60000970000197901057533030303243 off 

naa.60000970000197901057533030303336 off 

naa.60000970000197901057533030303337 off 

true

eqresxi15.mydomain.com

naa.60000970000196800291533030303231 off 

naa.60000970000196800291533030303236 off 

naa.60000970000196800291533030303241 off 

naa.60000970000196800291533030303242 off 

naa.60000970000196800291533030303434 off 

naa.60000970000196800291533030303435 off 

naa.60000970000196800291533030303537 off 

naa.60000970000196800291533030303832 off 

naa.60000970000197901057533030303243 off 

naa.60000970000197901057533030303336 off 

naa.60000970000197901057533030303337 off 

true

eqresxi03.mydomain.com

naa.60000970000196800291533030303231 off 

naa.60000970000196800291533030303236 off 

naa.60000970000196800291533030303241 off 

naa.60000970000196800291533030303242 off 

naa.60000970000196800291533030303434 off 

naa.60000970000196800291533030303435 off 

naa.60000970000196800291533030303537 off 

naa.60000970000196800291533030303832 off 

naa.60000970000197901057533030303243 off 

naa.60000970000197901057533030303336 off 

naa.60000970000197901057533030303337 off 

true

eqresxi04.mydomain.com

naa.60000970000196800291533030303231 off 

naa.60000970000196800291533030303236 off 

naa.60000970000196800291533030303241 off 

naa.60000970000196800291533030303242 off 

naa.60000970000196800291533030303434 off 

naa.60000970000196800291533030303435 off 

naa.60000970000196800291533030303537 off 

naa.60000970000196800291533030303832 off 

naa.60000970000197901057533030303243 off 

naa.60000970000197901057533030303336 off 

naa.60000970000197901057533030303337 off 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I suspect the Web Client doesn't show the LUN when the Status is 'off'.

I suspect a script should follow the same concept.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos