Script Extracts and Examples (PowerCLI)

From vwiki
Revision as of 15:01, 20 August 2009 by Sstrutt (talk | contribs) (Minor editrs)
Jump to navigation Jump to search

Before being able to use any the following script you need to install...

Getting Started

On the first run you need to allow the Toolkit to run properly by running...

Set-ExecutionPolicy RemoteSigned

Connect to the Virtual Centre using the following command using your normal username and password (same as you'd use to log into the VI Client). You will need access to the servers on TCP 443.

Connect-VIServer -Server uklonvcp1 -User <user> -Password <pass>

VM Datastores

List of Virtual Machines, and their datastores (with usage)

$datastoreExp = @{N="Datastore"; E={ ($_ | get-datastore | select-object -first 1).Name }}
$diskSizeExp = @{N="Total Disk"; E={ ($_ | get-harddisk | measure-object -property CapacityKB -sum).Sum }}
get-vm | select Name, $datastoreExp, $diskSizeExp | sort -property Datastore,"Total Disk"