PowerShell, Scripts

PowerShell – vSphere PowerCLI – Export Datastore Capacity and Usage

Below is a PowerShell script I wrote within VMWare PowerCLI 5.5 which exports the current capacity and usage of datastores in a VMWare environment to a CSV file.

The exported details include;

  • the datastore name
  • the datastore capacity in GB
  • the freespace remaining on the datastore in GB
  • the state of the datastore

Again, please note this was created using PowerCLI version 5.5

You can also grab the full script here: Script


#PowerShell Script to Export Datastore Capacity and Current Datastore Usage to CSV file
#Script to be ran using vSphere PowerCLI
#Script created using vSphere PowerCLI 5.5
#April 2016

#vSphere ServerName
$VIServer = "VCS01"

#CSV File Export Location and File name
$exportcsv = "D:\datastore.csv"

add-pssnapin VMware.VimAutomation.Core
Connect-VIServer $VIServer
Start-Sleep -s 25
Get-Datastore | Sort-Object Name | Select Name,FreeSpaceGB,CapacityGB,State | Export-Csv $exportcsv -force

Advertisements

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 )

Google+ photo

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

Connecting to %s