## esxcli storage core device detached list
# Script variables
# Add-PSSnapin vmWARE.VimAutomation.Core
# $vcenter = "vcenter01"
$LunIDs = ("naa.60000970000498700406544040444047", "naa.60000970000498700406544040444048")
$mycluster = "cluster01"
# Connect to Vcenter
# Connect-VIServer $vcenter
## $SourceNaa = "C:\cPS\TEST\unmount_detach_datastore\NaaList.txt"
## $LunIDs = Get-Content $SourceNaa
## $mycluster = "cluster01"
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 $mycluster | Get-VMHost
Foreach($VMHost in $ClusterHosts)
{
Foreach($LUNid in $LunIDs)
{
Write-Host "Detaching" $LUNid "from" $VMHost -ForegroundColor "Yellow"
Detach-Disk -VMHost $VMHost -CanonicalName $LUNid
}
}
转载于:https://blog.51cto.com/549687/1980213