Home > Powershell Script > Powershell: Count The Number Of VM’s On A Datastore

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
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.