Difference between revisions of "Script Extracts and Examples (PowerCLI)"

From vwiki
Jump to navigation Jump to search
m (Minor correction)
m (Minor editrs)
Line 2: Line 2:
* [http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx Windows PowerShell]
* [http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx Windows PowerShell]
* [http://www.vmware.com/go/powershell VI Toolkit]
* [http://www.vmware.com/go/powershell VI Toolkit]
== 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 ==
== VM Datastores ==

Revision as of 15:01, 20 August 2009

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"