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