- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks a lot, i will have a check and update the status for this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- what is _.DeviceUID
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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