Created
February 2, 2020 21:21
-
-
Save manualbashing/c2d1217af322687525da3a3ada611b8b to your computer and use it in GitHub Desktop.
[Unmount and Detach Datastore from ESXi Host] #PowerCLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $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