PowerCLI

 View Only

 How to get mount status of datastore in host?

Jump to  Best Answer
Emerson Prado's profile image
Emerson Prado posted Feb 22, 2026 12:58 PM

Hi all,

I sometimes need to unmount a datastore from all hosts where it's mounted, and I need a PowerCLI way to check if the datastore is mounted to each specific host. I found in this thread a good command:

Get-Datastore <Datastore> -RelatedObject <Host>

But I don't know if it's enough to check its boolean result, or if I should go to datastore state instead:

Get-Datastore <Datastore> -RelatedObject <Host> | Select State

Questions:

  1. Does datastore state "Unavailable" means it's unmounted, or it's mounted, but problematic?
  2. Which of the two commands above is the right one to tell if datastore is mounted in host?

Thanks!

JStars's profile image
JStars  Best Answer

normally if Get-Datastore <Datastore> -RelatedObject <Host> returns something, that means the DS is mounted. Else it won't return anything. If you need something to feed into an automation the code is not straightforward:

$vmhost = Get-VMHost <Host>
$ds = Get-Datastore <Datastore>

$vmhost.ExtensionData.Config.FileSystemVolume.MountInfo |
Where-Object { $_.Volume.Name -eq $ds.Name } |
Select-Object @{N='Datastore';E={$_.Volume.Name}},
@{N='Mounted';E={$_.MountInfo.Mounted}}


Emerson Prado's profile image
Emerson Prado

Thanks, @JStars! Would something like this be a safe choice?

$unmount_ds = "<Datastore>"
Get-VMHost |
ForEach-Object -Process {
  If (Get-Datastore $unmount_ds -RelatedObject $_) {
    <Unmount $unmount_ds from $_>
  }
}

Also, in the opposite case - Unmount all datastores from a specific host, would this be a good idea?

$unmount_host = "<Host>"
Get-VMHost $unmount_host |
Get-Datastore |
ForEach-Object -Process {
  <Unmount $_ from $unmount_host>
}

JStars's profile image
JStars

it seems ok to me.. just missing some error handlers but yes

Emerson Prado's profile image
Emerson Prado

Thanks a lot, @JStars!

svillar's profile image
svillar

I have never found a way to stop the APD alerts on removed datastores, no matter if I unmount, detach, etc.  No matter what I do, the host alerts as soon as I remove the storage presented from the array to the hosts.  It's annoying.