23 lines
953 B
PowerShell
23 lines
953 B
PowerShell
$Datastores = @"
|
|
VMTEST2_1_A9K_SYS
|
|
"@
|
|
$Datastores = ConvertTo-Array -MultiLineString $Datastores
|
|
|
|
foreach ($Datastore in $Datastores) {
|
|
$Datastore = Get-Datastore $Datastore
|
|
$VMhosts = $Datastore | Get-VMHost
|
|
$canonicalName = $Datastore.ExtensionData.Info.Vmfs.Extent[0].DiskName
|
|
$lunUuid = (Get-ScsiLun -VmHost $VMhosts | Where-Object { $_.CanonicalName -eq $canonicalName }).ExtensionData.Uuid | Select-Object -First 1
|
|
$storSys = Get-View $VMhosts.ExtensionData.ConfigManager.StorageSystem
|
|
$device = $storSys.StorageDeviceInfo.ScsiLun | Where-Object { $_.CanonicalName -eq $canonicalName }
|
|
#unmount disk
|
|
if ($device.OperationalState[0] -eq 'ok') {
|
|
$storSys.UnmountVmfsVolume($Datastore.ExtensionData.Info.Vmfs.Uuid)
|
|
}
|
|
#detach disk
|
|
$storSys.DetachScsiLun($lunUuid)
|
|
#rescan hosts
|
|
foreach ($VMhost in $VMhosts) {
|
|
Get-VMHost $VMhost | Get-VMHostStorage -RescanAllHba -RescanVmfs
|
|
}
|
|
} |