Home > Blogs > VMware PowerCLI Blog

Back to Basics: Connecting to vCenter or a vSphere Host

Following my previous post which took you through the install of PowerCLI I thought it was time to add another back to basics (B2B) post and show how to take the first step in using PowerCLI… Connecting to your vCenter or vSphere host.

Yes, PowerCLI can be used to connect to both vCenter and also the vSphere host independently, of course not all the cmdlets will be relevant if you connect to just the host but still, this can be useful during the initial setup or automated deployments of the complete infrastructure.

How to connect

If you are connecting to either a vCenter server or a vSphere Host the cmdlet is the same, you can use the Connect-VIServer cmdlet to connect to both of these (even at the same time), lets take a look at an example:

C:\PS>Connect-VIServer -Server vcenter01 -User admin -Password pass

In the above example you can see we are connecting to our vCenter server called “vcenter01” with a username and password to gain access to the vCenter server, we did not specify a protocol or port, by default HTTPS and port 443 is assumed which is the same as the vSphere Client or Web Client, unless you specify a –port or –protocol parameter for the cmdlet.


In the example above we used the –User and –Password parameters to pass through the credentials but this might not always be what you want to do, especially as PowerShell files are plain text!  There are multiple ways in which we can specify the credentials or store the credentials, its really up to you which you use and which is best suited for your situation.

Continue reading

PowerCLI 5.1 Release 2 Now Available

PowerCLI 5.1 Release 2 has now been released and can be downloaded here.  As always you will find some great new features, bug fixes and enhancements which make PowerCLI even better than before… I know its hard to believe but its true.

VDS Cmdlets

PowerCLI SnapinsWhenever I would ask the question at VMUG’s or VMWorld, “What would you like to see next from PowerCLI” I would always get the same answer “Support for Virtual Distributed Switches!”.

Previously there has been a fling available and also some work created by community member “Luc Dekens” to use VDS, this was a great start but in some cases was not a sustainable solution as it was either not supported or more complicated to maintain or use.

I am now pleased to tell you that PowerCLI has a new snapin, this snapin is called VMware.VimAutomation.VDS and is for managing Virtual Distributed Switches.

Introduced are 14 new cmdlets which will allow you to perform actions against your VDS configuration, we can use the Get-VdsCommand cmdlet to list the new cmdlets.

An overview of these are below:

Cmdlet Name Cmdlet description
Add-VDSwitchPhysicalNetworkAdapter This cmdlet adds host physical network adapters to a distributed switch.
Add-VDSwitchVMHost This cmdlet adds hosts to the specified distributed switch.
Export-VDPortGroup This cmdlet exports the configuration of a specified distributed port group to a specified .zip file.
Export-VDSwitch This cmdlet exports the configuration of a specified vSphere distributed switch to a .zip file.
Get-VDPortgroup This cmdlet retrieves distributed port groups.
Get-VDSwitch This cmdlet retrieves vSphere distributed switches.
New-VDPortgroup This cmdlet creates distributed port groups.
New-VDSwitch This cmdlet creates vSphere distributed switches.
Remove-VDPortGroup This cmdlet removes distributed port groups.
Remove-VDSwitch This cmdlet removes vSphere distributed switches.
Remove-VDSwitchPhysicalNetworkAdapter This cmdlet removes host physical network adapters from the distributed switches they are connected to.
Remove-VDSwitchVMHost This cmdlet removes hosts from the specified distributed switches.
Set-VDPortgroup This cmdlet modifies the configuration of distributed port groups.
Set-VDSwitch This cmdlet modifies the configuration of vSphere distributed switches.

Remember each of these cmdlets has help built in, to access the help including examples of how you might use these cmdlets use the following:

Get-Help cmdletname –full

PowerShell v3 Support

As well as the new cmdlets for working with Distributed switches and all the other great enhancements in PowerCLI 5.1 Release 2 we made sure we listened to our customers and with the release of PowerShell version 3 it seams that a lot of people are already making use or planning to install PowerShell v3.

You will be happy to know that PowerCLI now supports PowerShell v3, this not only gives you support from VMware but also we are now able to take advantage of some of the great enhancements which PowerShell v3 brings.

Some PowerShell v3 examples…

Simplified Syntax… Making PowerShell and therefore PowerCLI easier to read and quicker to type we can use simplified syntax to give us even more English like statements, before we would have needed to use the {} brackets to compare a property, now we are able to type it the same way we would think it…


The above simple example shows all virtual machines which are powered on.

vCloud Director 5.1 Support

With PowerCLI 5.1 R2 we have also added support for vCloud Director 5.1, you can now automate the latest version of vCloud director using both PowerCLI and PowerCLI for tenants in a vCloud Director 5.1 environment.


Let’s Make New-VIProperty Easier

New-VIProperty is a powerful PowerCLI cmdlet and it has been a part of the product since PowerCLI version 4.1. Several releases later, we are under the impression that it is still not widely used. If you take a look around the community, it is easy to find scripts which will would be easier to understand and also work faster if they were refactored to use the New-VIProperty cmdlet.

This blog post is not about how New-VIProperty works. There are several great blog posts on the internet which already explain how the cmdlet works and what its benefits are. Some of them are:

We understand that using New-VIProperty is not that easy. There are a lot of things that should be considered when you create a property – the name of the type you want to customize, the name of the API property, etc.

This blog post includes a PS module whose purpose is to make the use of New-VIProperty easier, the module can be downloaded from here.

Once you import this module into your PowerCLI session, you will be able to:

  • Benefit from tab-completion for the New-VIProperty cmdlet
  • Inspect which types are customizable with New-VIProperty
  • Inspect the properties of a particular customizable type in depth

Let’s take a look at the tab-completion feature

We can start creating a new property by entering “New-VIProperty –ObjectType“. Then, if we press the Tab key, we will iterate through the valid values for the ObjectType parameter.


Of course, when we know the first letters of the type we want to customize, we can enter them before pressing the Tab key. In this case, pressing the Tab key will iterate only through the types whose names start with the provided letters.


In the screen above, pressing the Tab key will show types like VirtualMachine, VirtualPortgroup, VirtualSwitch, etc.

If we are creating a value-based property, after the type has been defined, we should specify the API property with the –ValueFromExtensionProperty parameter. Now this is much easier using tab-completion.


So the type is VirtualMachine, and let’s say we want to add ToolsVersion. It is part of the Guest API property. So we can just enter “G” and then press Tab key. This time the tab-completion feature will search for all properties starting with “G” within the VirtualMachine backing API type. The first match is “Guest”.

After that we should add a dot and start pressing Tab until the desired property appears.


The Guest property has several sub-properties and after several hits on the Tab key we will reach the “ToolsVersion” property. The only thing left to do is give our new property a name. We will do this manually.


Tab-completion also works for the –BasedOnExtensionProperty parameter when you are creating a script-based property.

The second enhancement is the ability to retrieve the list of customizable types

The provided PS module exports the Get-VIPropertyValidTypeNames function. By default, it returns the complete list of types which we can customize using New-VIProperty.

Each type is represented by a PSObject with the following properties:

  • TypeName – represents the string that New-VIProperty accepts through the ObjectType parameter
  • IsManaged – indicates whether the backing API type is managed or not. For more information about managed and data object types, see the vSphere API SDK documentation
  • VimTypes – a list of the backing API types. Knowing which is the backing type of a cmdlet type could be useful; for example, we can refer to the vSphere API SDK documentation for a more detailed description of the API type.


The function provides three filter parameters which let you reduce the list of types. Run “Get-Help Get-VIPropertyValidTypeNames” for more information.

The last enhancement is another function named Get-VIPropertyHelperObject.

This function accepts the name of a customizable type and returns a helper PSObject which could be used for:

  • Inspecting the backing API type
  • Searching API type properties by name
  • Creating VI properties easily

Let’s see this in action. Let’s pass VMHost to the function and save the result in the $helper variable.

The structure of the helper object is based on the backing API object. It has the same set of properties, but their purpose is informative. The output of this object looks like this:


At the top we can see the cmdlet type –VMHost – and the backing API type – HostSystem.

The list of all API type properties follows. For each property, the type is also displayed.

A plus symbol in front of the property indicates that it has sub-properties and it is browsable. For example, if you write $helper.Config, you will see all the properties of Config.


The helper object also has a method named SearchProperties. It searches all properties and sub-properties by name.

Let’s assume that we want to add a property to all VMHosts which shows the vendor of the hardware box. We also know that there is a ‘Vendor’ property in the API object, but we are not sure where it is defined, so we can call $helper.SearchProperties(‘Vendor’).


The output contains all properties whose names contain ‘Vendor’. The last one is the property that we’re looking for.

The next step is creating a property and this is really easy with the helper object. The only thing that we have to do is to call this line: $helper.Summary.Hardware.Vendor.CreateValueProperty()

The helper object provides an identical method for each property within the whole structure. This method creates a VI property using the New-VIProperty cmdlet.


We can see that the method first shows the New-VIProperty expression which will be executed. Below this line, you can see the result of running the New-VIProperty cmdlet.

Let’s see the result of our actions:


This method is really useful for an interactive PowerCLI session, but what about if we want to create a VI property within a script. The helper object provides two methods named GetValuePropertyCreationCode and GetScriptPropertyCreationCode.

Both methods build and return a New-VIProperty expression which you can copy, paste and modify in your script.


Three of the methods have a parameter which accepts the name of the new VI property. If it is not specified (as it is not in the examples), a name will be selected automatically.


In conclusion, this module allows you to:

  • Inspect API types easily and search their properties by name
  • Create VI properties or generate New-VIProperty expressions to use in a script
  • Retrieve the list of customizable types
  • Use tab-completion within the New-VIProperty cmdlet

Finally, let’s see where New-VIProperty is applicable and why it is better to use:

    • If you have a Select expression using hash table syntax
      • Get-X | Select-Object -Property Name,@{Name=”NestedPropertyName”;Expression={<some expression over $_>}}
    • If your script needs data from the ExtensionData/View
      • foreach ($vm in $vms) { ….. $foo = $vm.ExtensionData.foo …..}
    • The code look better
    • The scripts are faster


Download the module from here and import it into your session.

What Next?

If you find this module helpful or have any other comments on this feature we would love to hear them, the PowerCLI team at VMware constantly tries to make PowerCLI a better product and a product which is easy to use, let us know what you think of this and if you would like to see things like this backed into the release of PowerCLI.


imageThis post was created by Vitali Baruh…

Vitali joined VMware and PowerCLI team in the beginning of 2009. He is member of the quality engineering part of the team and his main role is the functional verification of the vSphere, vCloud and License PowerCLI components.

As all members of the team he is working to deliver a good and valuable product. He is also working to improve all processes and tools involved in product development and validation.

PowerCLI 5.1 and the future

Recently I have had some questions from people using PowerCLI, these are mainly related to confusion around the 5.1 release of VMware products and the way that PowerCLI works so I wanted to use this blog post to answer some of these questions but also to confirm that the future for PowerCLI is bright.

Q.  “Does PowerCLI work with the vCenter Server Appliance?”image

A. Yes it does, PowerCLI uses the vCenter APIs, in fact the best place to install PowerCLI is the same place that you would use the vSphere Client from, this is normally the vSphere admins workstation or a windows machine used solely for scheduled tasks.  PowerCLI connects to the vCenter APIs and therefore both Windows and the appliance versions of vCenter work with PowerCLI 5.1.

Q. “Does PowerCLI work with the vSphere Web Client?”

A.  A common question and yet in reality you do not need the C# vSphere Client or the vSphere Web Client in order for PowerCLI to work, everything you need is inside the installer for PowerCLI, just install it (instructions here) and your set.

Q. “With VMware releasing more and more Linux related appliances what does this mean for PowerCLI?”

A. PowerCLI is one of VMware’s most successful and well loved automation and troubleshooting tools by vSphere and vCloud Director Admins, as I said in the answer to a previous question, it connects directly to the vSphere APIs, it doesn’t care what is hosting them.

Whilst I can not discuss the roadmap for PowerCLI I can certainly say its as strong as ever and we will continue to wow the users of PowerCLI with the latest features and updates.

Q. “Does Onyx work with vSphere 5.1?”image

A. For those of you who are not aware of what Onyx is, it’s a VMware Fling which sits in-between your vCenter and your vCenter Client, it intercepts the traffic and translates it into PowerShell code, not nicely formatted PowerCLI type cmdlets but still a great place to look if you need to find a way to do something quickly.

You hit play on the Onyx client and the fun begins, anything you do in the vSphere client from then on is captured and represented as code, and not just PowerShell code but also C#, vCO JavaScript and  Raw SOAP messages.

So does it work with 5.1 ?  Yes of course it does, but only when using the C# client, obviously the vSphere Web Client works differently and therefore Onyx is unable to capture the actions you take in the web client and turn them into code, as this is a fling I can not make any promises of if or when this will be updated to work with the web client but obviously the challenges are different.  In the meantime make sure you use the C# client when you want to capture the code.

Hopefully this will help eliminate any questions about PowerCLI and how it works with 5.1 and the future, if you have any further questions please add a comment to this post and we will do our best to answer them.

What’s new in PowerCLI 5.1–Datastore Clusters

As with previous releases of PowerCLI we constantly improve the number of cmdlets and enable the ability to work with some of the latest features.  With the recent release of PowerCLI 5.1 we have introduced the ability to work with Datastore Clusters.  This can be useful for the following scenarios:

  • Setting up new datastore clusters
  • Adding multiple datastores to datastore clusters
  • Adding multiple VMs to a datastore cluster
  • Removing datastore clusters
  • Configuring datastore clusters on mass
  • Automating the testing of datastore clusters

New Datastore Cluster Cmdlets

The following datastore cluster cmdlets are available for use:

Name Synopsis
Get-DatastoreCluster Retrieves datastore clusters.
New-DatastoreCluster Creates a new datastore cluster.
Remove-DatastoreCluster Deletes the specified datastore clusters.
Set-DatastoreCluster Modifies the configuration of the specified datastore cluster.

As well as these datastore cluster cmdlets you can also use the Move-Datastore cmdlet to move datastores into datastore clusters, an example of this can be seen below:

$myDatastoreCluster = Get-DatastoreCluster -Name “MyDatatoreCluster”

Get-Datastore “MyDatastore1”, “MyDatastore2” | Move-Datastore -Destination $myDatastoreCluster

Additional to this, the VM cmdlets have been adjusted to receive a datastore cluster as well as a datastore so when a VM is created or altered these can use datastore clusters, the cmdlets can also be used to define storage DRS rules, an example of this can be seen below:

$vmhost = Get-VMHost -Name MyVMHost1
$myVM = Get-VM -Name WindowsXP
$mySourceTemplate = Get-Template -Name WindowsTemplate
$myDatastoreCluster = Get-DatastoreCluster -Name MyStorageCluster1
$myAdvancedOption =
New-Object ‘VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.SdrsVMAntiAffinityRule’ $myVM


New-VM -Name VM -Template $mySourceTemplate -Datastore $myDatastoreCluster -AdvancedOption $myAdvancedOption -ResourcePool $vmhost

Continue reading

Meet the PowerCLI Team

I have often been asked who creates PowerCLI and to pass on your appreciation to the people who have saved you so much time and effort.

So after visiting Bulgaria on my way back from VMworld Barcelona I thought it would be nice to show you a recent picture of the PowerCLI Team who are located in Sofia, Bulgaria.

Feel free to leave your comments to them as a comment on this post.


PowerCLI at VMworld 2012 Barcelona

Following on from the great sessions at VMworld San Francisco, PowerCLI will also be coming to VMworld Barcelona, there are some great sessions, labs and discussions available for you to watch, make sure you add these to your schedule now !

INF-VSP1252 – What’s New with vSphere 5.1 – ESXCLI & PowerCLI

Click here to add
In this session Technical Marketing automation experts William Lam and Alan Renouf will take you through VMware Automation.

You will learn which products are available, which products to use and how Automation fits into the VMware Suite of products. In this session Alan and William will take you through the exciting features available to use when automating VMware products, both beginners and experts will learn how to use new features to make your life easier and more productive.

Thursday, Oct 11, 1:30 PM – 2:30 PM

William Lam – Sr. Technical Marketing Engineer, VMware, Inc.

Alan Renouf – Sr. Technical Marketing Architect, VMware, Inc.

INF-VSP1329 – PowerCLI Best Practices: The Return!

Building on the success of our PowerCLI Best Practices sessions from VMworld 2011, we want to show you our next collection of PowerCLI best practices. This session will show and demonstrate PowerCLI in all its aspects managing and automating not just VMware vSphere® but also VMware vCloud Director®, VMware® View™, VMware vShield™ and more Thursday, Oct 11, 9:00 AM – 10:00 AM

Alan Renouf – Sr. Technical Marketing Architect, VMware, Inc.

Luc Dekens – Systems Engineer, Eurocontrol Maastricht.

Group Discussions

GD33 – PowerCLI with Alan Renouf

During this group discussion we will talk about what can be automated, discuss the merits of using PowerShell and PowerCLI, show examples and talk about the best methods of achieving integration. We will also discuss tips and tricks you have learned and the best methods for automating the VMware products. Come prepared with examples and questions and remember this is a Group Discussion! Wednesday, Oct 10, 11:00 AM – 12:00 PM

Alan Renouf – Sr. Technical Marketing Architect, VMware, Inc.

Hands on Labs

HOL-INF-10 – Script and Develop Your Cloud Solution with PowerCLI and the vSphere Web Client SDK

This lab is presented as two 30 minute lightning labs to help you extend your VMware solution. The PowerCLI module covers automating vSphere and vCloud Director. Novice users will learn to use the tool and more advanced users will get familiar with the new functionality available in the latest release of the product. You will walk away with a better understanding of PowerCLI and how it can help you in your day-to-day work. The vSphere Web Client SDK module teaches you several techniques for extending the vSphere Web Client. The goal of this module is to demonstrate the close integration that is possible with the vSphere Web Client SDK, and the ease with which you can integrate your own solutions into the vSphere Web Client. HOL

Attend the self paced Hands on Lab.

Meet the Experts

EXPERTS04 – Meet the Experts – 04

Have some specific PowerCLI questions ? Stop by the Meet the Experts Lounge to book time with a Knowledge Expert. They are available throughout the week for casual, one-to-few discussions. Please reference their availability now and stop by the Lounge reception desk in Hall 6, to schedule a 30-minute appointment. Tuesday, Oct 9, 5:00 PM – 6:00 PM


Still cant decide ? Take a look at some of the session videos where the presenters explain more information…..

PowerCLI 5.1 Poster

Following the release of PowerCLI 5.1 there is of course a new PowerCLI Poster, those of you who attended VMworld San Francisco may have been lucky enough to grab one of the few posters we had there, they went very quick and I’m sorry to the people who did not get one.

We plan on having some at VMworld Barcelona (No guarantees) so make sure you attend some of the PowerCLI sessions to get your copy.

In the meantime, for those of you who could not wait and want to print your own copy right now please find below the latest PowerCLI 5.1 poster including a list of all the new cmdlets and the cmdlets in the new PowerCLI for vCloud Tenants snapin.

Download the poster here, this is ideal for printing on large printers or even just keeping on the iPad or as a PDF for reference.

PowerCLI Poster

PowerCLI 5.1 now available

PowerCLI 5.1 is now generally available, as a reminder, in the previous post we gave you an update of what was new.  You can view that post here.

You can view the official PowerCLI release documentation here or the documentation for the Tenant snapin here.

From now on you will see two download links for PowerCLI, one for the updated version of PowerCLI and another for the Cloud Tenants, make sure you choose the correct one as they will not install together.

As you can see from the download page, the updated PowerCLI for vSphere and vCD Administrators is on the left hand side and the PowerCLI for Tenants of vCloud Director is on the right.

Stay tuned for more posts showing exactly what is possible with these new releases soon.Download PowerCLI


Use the following link to be directed to the download page:  http://communities.vmware.com/community/vmtn/server/vsphere/automationtools/powercli?view=overview

PowerCLI 5.1 – What’s New ?

With the announcement of vSphere 5.1 from Steve Herrod at VMworld 2012 – San Francisco I wanted to highlight the new features which will be available as part of VMware vSphere PowerCLI 5.1 Release 1.



As with previous releases there have been many enhancements to PowerCLI, as users of PowerCLI will know, as part of the default PowerCLI 5.0.1 install we already had 5 PowerShell Snapin’s available to use, these enabled you to manage the following products and features:

  • vCenter and vSphere (VMware.VimAutomation.Core Snapin)
  • vCenter and vSphere Licensing (VMware.VimAutomation.License Snapin)
  • Image Builder (VMware.ImageBuilder Snapin)
  • Auto Deploy (VMware.DeployAutomation Snapin)
  • vCloud Director (VMware.Vimautomation.Cloud Snapin)

As you will also know, most of the cmdlets for the Cloud snapin were “Get-“ cmdlets, these allowed us to focus on retrieving data from vCloud Director, access to more advanced functions were available via the Get-CIView cmdlet but this was for the advanced PowerCLI users.

What’s New for vSphere Users ?

The PowerCLI Core Snapin introduces a number of improvements and new features, you will of course find many bug fixes and speed enhancements as part of this release, as well as this the following enhancements have been included:

  • You can use Kerberos for pass-through authentication with vCenter Server, ESX/ESXi, and vCenter Virtual Appliance systems.
  • You can create linked clones with New-VM.
  • You can pass datastore clusters to the Datastoreparameters.
  • You can retrieve vSphere objects from vCloud Director objects with the RelatedObjectparameter.
  • You can manage resources more efficiently with Storage DRS (SDRS) support added to a number of cmdlets.
  • You can retrieve, create, modify, and remove VMHost, VM, and SDRS advanced settings with the the Get-AdvancedSetting, New-AdvancedSetting, Set-AdvancedSetting, and Remove-AdvancedSetting cmdlets.

vSphere PowerCLI 5.1 Release 1 also brings a set of improvements that enhance security and customization, these include:

  • You can set the scope of your settings with the Scope parameter of Set-PowerCLIConfiguration.
  • You can initialize custom vSphere PowerCLI scripts automatically by storing them in the Initialize-PowerCLIEnvironment_Custom.ps1 script configuration file.

What’s New for vCloud Admins ?

vCloud Director Admins can take advantage of over 60 cmdlets to manage vCloud Director, these have been enhanced from the “Get-“ cmdlets and now include cmdlets to help you modify and automate your vCloud Directory infrastructure, the following enhancements have been made:

  • You can create, modify, manage, and remove organizations.
  • You can create and manage permissions.
  • You can assign computing and networking resources.
  • You can create, modify, and remove organization networks.
  • You can create, modify, and remove vApp networks.
  • You can create, modify, manage, and remove vApps.
  • You can manage virtual machines and their guest operating systems within vApps.

What’s New for vCloud Tenants ?

With PowerCLI 5.1 Release 1 we now have a new snapin specifically for vCloud Tenants, in fact this is a completely separate installation with its own set of cmdlets which can not be installed on the same machine as vSphere PowerCLI 5.1 Release 1, this is called VMware vSphere PowerCLI Release 1 for Tenants and is designed to aid the vCloud Tenants in performing automated tasks in their hosted vCloud organization.

Why would we do this ?

We wanted to bring the power of automation and the ease of reporting that PowerCLI gives the current vSphere and vCloud Admins to the tenants of the cloud.  All this whilst giving them an easy to use simplified subset of cmdlets specific to the tasks they can do within their vCloud Organization.

What’s available to tenants ?

VMware vSphere PowerCLI 5.1 Release 1 for Tenants consists of two components:

  • vSphere PowerCLI common snapin for providing common PowerCLI configuration and usage based tasks, these cmdlets are part of the VMware.VimAutomation.Commonsnapin.
  • vCloud Director PowerCLI snapin for providing tenant-based reporting and automation, these cmdlets are part of the VMware.VimAutomation.Cloud snapin and can be used with vCloud Director 1.5.1 Tenant tasks.

These components will allow the vCloud Tenants to perform the following tasks:

  • You can list, modify, and manage organizations.
  • You can list, create, and manage permissions.
  • You can list and assign networking resources.
  • You can list organization networks.
  • You can list, create, modify, and remove vApp networks.
  • You can list, create, modify, manage, and remove vApps.
  • You can list and manage virtual machines and their guest operating systems within vApps.


So where are we now ? What can we actually do with PowerCLI and the different VMware installations of snapins ?


As you can see, we have a number of different snapins which enable us to add the products and areas we are interested in using with Windows PowerShell, we have the ability to not only enable our admin users but also our private and public cloud users, with the VMware snapins all users of the VMware products can achieve the level of automation, integration and reporting that PowerShell and PowerCLI gives.

More Information

Keep tuned for more blog posts and information or if you are visiting VMworld Europe in 2012 make sure you add  INF-VSP1252 – What’s New with vSphere 5.1 – ESXCLI & PowerCLI to your session list.