Getting Started with PowerCLI 5.1 and PowerShell 3.0

In this post i am going to give a quick startup guide to the new version of PowerCLI 5.1 with the Windows Management Framework 3.0, which is available with Windows 8. Both are recently published releases of the great PowerShell scripting engine that every VMware admin should know. First i am going to give a quick guide how to set up and configure your environment. Later i am going to show the new features of PowerCLI 5.1 and PowerShell 3.0.

How to set up PowerCLI 5.1 with PowerShell 3.0

Download and Install PowerShell 3
If you're running Windows 8 already, you can skip this step. Windows 8 comes with PowerShell 3 out of the box. If you're running Windows 7 you have to download and install the Windows Management Framework (WMF) 3.0: http://www.microsoft.com/en-us/download/details.aspx?id=34595

Set ExecutionPolicy
For security, you can't run PowerShell scripts by default. You have to set the ExecutionPolicy. That has to be done as Administrator. Right-Click Windows PowerShell, select "Run as Administrator..." and enter:

Set-ExecutionPolicy RemoteSigned

Create a Profile
Open PowerShell again with your user to configure the profile. The profile is a configuration file that is loaded when you start the PowerShell. It is usually located at C:\Users\<USER>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1.

Create and open your profile with:

New-Item -Path $Profile -ItemType file -Force
notepad $profile

Notepad will open with an empty file. Enter the following command and save the file. The "SilentlyContinue" will prevent the error message "Cannot add Windows PowerShell snap-in VMware.VimAutomation.Core because it is alerady added. Verify the name of the snap-in.":

Add-PsSnapin VMware.VimAutomation.Core -ea "SilentlyContinue"

The PowerShell is now ready to go!
Connect to your vCenter Server and run your first command to get a list of virtual machines managed by the vCenter Server:

Connect-VIServer <VCENTER> -User <USER> -Password <PASSWORD>
Get-VM

What's new with PowerCLI 5.1

Datastore Cluster Support
You can create and modify Datastore Clusters and pass Datastore Clusters to the Datastore parameters. The Datastore Cluster Support was really missing in PowerCLI 5.0 and it is really great that is is now fully supported. Example:

vCloud Director Support
There are plenty new cmdlets for the vCloud Director but this is not the scope of this post.

What's new with PowerShell 3.0

Where statement is simplifiedThe curly brackets ({}) and the placeholder ($_.) are no longer required. This will make the script more easy to read. Let's do a quick example. All the following commands are doing the same:

Auto-Complete
The new Integrated Scripting Engine (ISE) has a auto-complete feature that saves time, and reduces typos:

PowerShell 3.0 IntellisenseThe new PowerShell does live syntax checking. When you make mistake it will underline the error in red and gives a suggestions to correct the error:

Explore cmdlets
The cmdlet called Show-Command gives beginners a great opportunity to research and play around with the syntx of cmdlets. Show-Command is a GUI for creating commands:

New Out-GridView Parameter
The Out-Gridview cmdlet now has the -passthru parameter. This gives us a possibility to interact with the user. The user can choose which objects he want's to get processed by the script. Example: