satheeshsatz
Enthusiast
Enthusiast

Remove Detached LUN from esxi

i am using esxcli storage core device detached remove -d NAA.ID to remove the detached(status=off) LUNs from each esxi hosts individually.

how can i use powercli script to identify the detached LUNs(esxcli storage core device detached list) and remove it from the host.

LucD

Regards, Satheesh
LucD
Leadership
Leadership

You can do

$esxName = 'MyEsx'

$esx = Get-VMHost -Name $esxName

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

$esxcli.storage.core.device.detached.list.Invoke() | %{

    $detach = @{

        device = $_.DeviceUID

    }

    $esxcli.storage.core.device.detached.remove.Invoke($detach)

}

Or, as an alternative, remove them all in one call

$esxName = 'MyEsx'

$esx = Get-VMHost -Name $esxName

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

$detach = @{

    all = $true

}

$esxcli.storage.core.device.detached.remove.Invoke($detach)


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

satheeshsatz
Enthusiast
Enthusiast

thanks  a lot, i will have a check and update the status for this.

Regards, Satheesh
Reply
0 Kudos
mammadshah
Contributor
Contributor

Hello,

I am trying to remove all non-accessible datastore and found this discussion. could you explain the following line in the script

$detach = @{

        device = $_.DeviceUID

    }

I have executed the following and found no outcome.

  1. what is _.DeviceUID
  2. How its defines and removed Datastore/inaccessible data store ?

PS C:\Users\vmuser>$detach = @{device = $_.DeviceUID }

PS C:\Users\vmuser> echo $detach

Name                           Value

----                           -----

device

PS C:\Users\vmuser>

thanks

Reply
0 Kudos
LucD
Leadership
Leadership

You have to execute the above script from a .ps1 file.

The $_ variable contains the object in the pipeline from the foreach statement.

Copy the code into a .ps1 file, then execute the .ps1 file by giving the path to the .ps1 file at the PS prompt.


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

Reply
0 Kudos