Powershell: Count The Number Of VM’s On A Datastore
Getting information like number of VM’s on a specific datastore is easy within the VIC. You can get this information from the Datastores Summary tab. However, if for some reason you needed it scripted or were building a script that required this information to act on, here is how you could pull it.
param ($ds)
Get-Datastore -Name $ds| Foreach-Object {
$number = $_ | Get-VM | Select-Object Name
Write-Host $number.Count
}
Disconnect-VIServer -Confirm:$false
You can run this script from the command line by calling the script and specifying which datastore you want to run it against. For example: .\script.ps1 datastore1
Advertisement
Categories: Powershell Script