Getting Started with VMware vSphere PowerCLI

VMware are providing vSphere PowerCLI to make it possible to administer vSphere and vCloud Director using PowerShell.

A good startingpoint is the VMware vSphere PowerCLI Documentation page that is available at:

If you´re in a hurry you could follow my quick starting guide below:

Step 1. Download and install VMware vShere PowerCLI:
VMware vSphere PowerCLI is available for download from
Select the release you want to download from the drop-down list and click on the download-link.
Double-click on the downloaded installation-package and follow the instructions to install PowerCLI.

Step 2. Start PowerCLI and connect to a vCenter Server:
Double-click on the “VMware PowerCLI” icon to start PowerCLI.


Use the CmdLet ‘Connect-VIServer’ as shown below to connect to the vCenter Server:

Connect-VIServer -Server <server-IP> -Protocol https -Username '<Username>' -Password '<Password>'

Now you are ready to explore and manage the VMware vCenter environment using PowerShell. Start by executing the following CmdLet to list all available commands.



Powershell makes it really easy to compare text-files, just use the following oneliner to compare two files:

Compare-Object -ReferenceObject (Get-Content c:pathtofile1.txt) -DifferenceObjet (Get-Content c:pathtofile2.txt)


PowerShell Remoting

First of all Powershell Remoting must be enabled on the machine you are going to manage. The command ‘Enable-PSRemoting -Force’ starts the WinRM service, changes its startup mode to automatic and creates a firewall-rule that allows incoming connections.

You can test the connection by entering the following Powershell command from an remote computer:

The result should look something like in the following example:
PS C:UsersTestUser> Test-WsMan TESTCOMPUTER

wsmid :
ProtocolVersion :
ProductVendor : Microsoft Corporation
ProductVersion : OS: 0.0.0 SP: 0.0 Stack: 3.0

To create a remote session, enter the following command:
Enter-PSSession -Computername -Credential <domainusername>


Initialize, partition and format disks using PowerShell

I ran into this good blogpost about using PowerShell to Initialize Raw Disks, and to Partition and Format Volumes.

To summarize, you can initialize raw disks and partition and format volumes using the following simple PowerShell “script”:
Get-Disk | Where partitionstyle -eq ‘raw’ | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel “disk2” -Confirm:$false

Use PowerShell to Find Service Accounts

I was looking for a way to find service accounts using PowerShell and found the following post on the “Hey, Scripting Guy! Blog”:

To summarize, you can use the Get-WmiObject cmdlet to retrieve information about service accounts as in the following example:

Get-WmiObject win32_service | format-table Name, StartName