Skip to content

Instantly share code, notes, and snippets.

@manualbashing
Created February 2, 2020 21:21
Show Gist options
  • Select an option

  • Save manualbashing/c2d1217af322687525da3a3ada611b8b to your computer and use it in GitHub Desktop.

Select an option

Save manualbashing/c2d1217af322687525da3a3ada611b8b to your computer and use it in GitHub Desktop.
[Unmount and Detach Datastore from ESXi Host] #PowerCLI
$esx = Get-VMHost *esx01*
$ds = Get-Datastore -VMHost $esx
$lun = Get-ScsiLun -VmHost $esx
$hostStorageSystem = Get-View $esx.Extensiondata.ConfigManager.StorageSystem
foreach ($uuid in $ds.ExtensionData.info.Vmfs.uuid)
{
Write-Host -ForegroundColor Magenta "Unmounting Volume $uuid"
$hostSTorageSystem.UnmountVmfsVolume($uuid)
}
foreach ($uuid in $lun.CanonicalName)
{
Write-Host -ForegroundColor Green "Detaching Lun $uuid"
$hostStorageSystem.DetachScsiLun($uuid)
}
foreach ($uuid in $lun.CanonicalName)
{
Write-Host -ForegroundColor Green "Attaching Lun $uuid"
$hostStorageSystem.AttachScsiLun($uuid)
}
Get-VMHostStorage -RescanAllHba -RescanVmfs -VMHost $esx
foreach ($uuid in $ds.ExtensionData.info.Vmfs.uuid)
{
Write-Host -ForegroundColor Magenta "Mounting Volume $uuid"
$hostSTorageSystem.MountVmfsVolume($uuid)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment