Tag Archives: PowerCLI

Checking you are up to date with PowerCLI

Now that PowerCLI is a module and in the PowerShell Gallery there have been a lot of releases and bug fixes, you would be forgiven for not having the latest version installed or even knowing what the latest version is.

With this in mind and with the latest 6.5.3 version triggering this in my mind, I created a function that checks your installed PowerCLI version against the one thats in the PowerShell Gallery online and lets you know if there is a new version.

Now of course this can be run manually and it will return the results letting you know which modules are out of date:

And once completed of course its easy to update PowerCLI to the latest version:

Even better why not add it to your profile. It does take a couple of seconds to run so maybe you will want to run it on a certain day past a certain time in your profile so it doesn’t slow down every launch of PowerShell you have, here is an example of what I have in my profile where I check every Wednesday after 2PM.

if ( ((Get-Date).tostring('%H') -ge "14" ) -and ( (Get-Date).DayofWeek -eq "Wednesday" ) ) {

Check-PowerCLIUpdate Script

Here is the function that allows you to check for updates:

Function Check-PowerCLIUpdate {
    #Based on great module by Jeff Hicks here: http://jdhitsolutions.com/blog/powershell/5441/check-for-module-updates/

    # Getting installed modules
    $modules = Get-Module -ListAvailable VMware* | Sort Version -Descending | Select-object -Unique

    #Filter to modules from the PSGallery
    $gallery = $modules.where({$_.repositorysourcelocation})

    # Comparing to online versions
    $AllUpdatedModules = @()
    foreach ($module in $gallery) {

         #find the current version in the gallery
         Try {
            $online = Find-Module -Name $module.name -Repository PSGallery -ErrorAction Stop
         Catch {
            Write-Warning "Module $($module.name) was not found in the PSGallery and therefore not checked for an update"

         #compare versions
         if ($online.version -gt $module.version) {
            $AllUpdatedModules += new-object PSObject -Property @{
                Name = $module.name
                InstalledVersion = $module.version
                OnlineVersion = $online.version
                Update = $True
                Path = $module.modulebase
    $AllUpdatedModules | Format-Table
    #Check completed


Retrieving NVMe details through PowerCLI

Recently I was contacted and asked if there was a way to retrieve information about the NVMe Drives in an ESXi host, this information is easily accessible via ESXCLI using the “nvme” namespaces.

Through PowerCLI this can be easily called and then each feature can be called under this namespace to give you detailed information on the NVMe devices in your ESXi host.  The reason they wanted to do this was to first check the firmware on all the NVMe devices in a cluster to see if they are at the latest revision.  Another reason they wanted this script was in case one of the NVMe devices was behaving differently than the others it would be an easy way to compare the devices.

You can see an example of the script running below:

Continue reading Retrieving NVMe details through PowerCLI

Automating the VSAN HCL with PowerCLI

Recently I was contacted by a customer who needed to be able to update their VSAN Hardware Compatibility List in the VSAN Health Check but was unable to do so via the GUI as their vCenter servers did not have internet access.

This is a common setup as a lot of customers clearly do not want their Server infrastructure having a direct connection to the internet due to strict security requirements. The problem is when the vCenter server needs to update the VSAN HCL database file it requires a connection to the internet to do this. Whats more, this specific customer had several VCs and was getting quite frustrated with the warning that the HCL database had not been updated. Rather than turning this feature off the customer was looking for a way to update the HCL from a computer that had internet access – his desktop.

New in PowerCLI 6.5 (backwards compatible to previous versions) is a cmdlet that will help us achieve this… Update-VSANHCLDatabase, as you can see from the below image this can be run either grabbing the database information directly from the internet or if you add the “FilePath” parameter you can load the database locally.

Continue reading Automating the VSAN HCL with PowerCLI

Automating the build of your vSphere 6.5 home lab

This year at VMworld SFO and BCN I was involved in organizing a couple of great hackathons with the @VMwareCode guys and William Lam, these were highly successful and I have to say the highlight of both my VMworlds.  The teams were great, the end projects were fantastic and most of all, everyone that attended told me they learned something, this if you ask me was the main objective for the hackathon.

If you attended I do want to extend a huge thanks for joining in, having fun and learning with us.


To put the hacakthon together we needed to build up some environments for people to use, William came up with the idea of using Intel NUCs as these were easily transportable and packed a punch for their size, the equipment we purchased is listed below:

Quantity: 2 Crucial 16GB Single DDR4 2133 MT/s (PC4-17000) SODIMM 260-Pin Memory – CT16G4SFD8213
Quantity: 1 Intel NUC Kit NUC6i3SYH BOXNUC6I3SYH Silver/Black
Quantity: 1 Samsung 850 EVO 500GB 2.5-Inch SATA III Internal SSD (MZ-75E500B/AM) (For Capacity)
Quantity: 1 Samsung SM951 128 GB Internal Solid State Drive MZHPV128HDGM-00000 (For Performance)

For the hackathon we needed to build a lot of these units, whilst we did some parts of it manually William and I recently took the time to complete the automated deployment of these units, in fact the script is not specific to these units, it will work on any ESXi host with 2 disks, one for performance and 1 for capacity.  Of course you can also adjust the script to use more disks if you have them!

Once you have ESXi on a USB insert it into the machine and configure it to boot from the USB, after the ESXi machine is on the network you can alter the configuration settings in the start of the script and run the script in the Deployment Script section of this blog to automate the following:

  • Configure VSAN in a single node configuration (Unsupported)
    • Use the smaller SSD for performance
    • Use the larger SSD for Capacity
  • Configure NTP on the ESXi Host
  • Enable SSH on the ESXi Host for debugging
  • Configure the Syslog settings on the ESXi Host
  • Deploy the VCSA on the ESXi Host
  • Enable VSAN Traffic on the Management Network
  • Create a Datacenter
  • Create a Cluster
  • Create a subscribed content library for William Lams Nested ESXi Library
  • Enable Autostart so the VCSA VM starts when the ESXi machine powers on
  • Enable SSH on the VCSA Server

Continue reading Automating the build of your vSphere 6.5 home lab

Working with maintenance mode in vROPs via PowerCLI

A while back I was contacted by someone who knew that PowerCLI now worked with vRealize Operations (vROPS) and knew it covered the entire API but was unsure how to get to the point where they could achieve what they wanted.

Before I go into what they were doing I highly recommend that if you are interested in learning what is available via VROPs and PowerCLI you check out the following awesome posts by John Dias

And specifically check out this post which tells you the more advanced feature of being able to access the entire API and create your own functions.

So, the story around this script was that this person was heavily using vROPs in their environment to monitor and troubleshoot their VMware infrastructure, they had it highly tuned but also used PowerCLI to automate some maintenance and updates of the infrastructure, the problem was that every time they performed these tasks they would get automated alerts from vROPs to tell them that things were down or not behaving correctly.

This while expected was clearly a pain as we all know that unwanted email from a monitoring system can get tedious and eventually ignored to the detriment of something important being missed.

Continue reading Working with maintenance mode in vROPs via PowerCLI

Adding a vGPU For a vSphere 6.0 VM via PowerCLI

I had a conversation with a VMware customer the other day and they were asking if there was a way to automate the addition and removal of a vGPU to a VM dynamically on a requested or scheduled basis, VMGuru has a great post here on what exactly a vGPU is, I highly recommend reading it.

They asked for a PowerCLI command or function to configure the VM graphics card, specifically to assign a vGPU resources to the VM, a desktop user’s VM is configured by default with vSGA (to not tie up  vGPU resources) then the user schedules the vGPU resource for a specific time frame using their end user portal, before the scheduled vGPU reservation time frame the user is logged out and the script would kick in. The script would reconfigure the VM settings and assigns a vGPU profile to it, the equivalent of what is being done in the UI as follows:


Continue reading Adding a vGPU For a vSphere 6.0 VM via PowerCLI

PowerCLI 6.0 R2 – The most advanced version VMware has ever made

imageThis week VMware released a new version of PowerCLI and this release is the most advanced version ever made.  As the Product Manager for PowerCLI I am particularly proud of this release as we not only add core functionality to the vSphere cmdlets allowing access to report, manage and automate even more of the core infrastructure but yet again we introduce a number of new features allowing PowerCLI to reach even further into the SDDC and automate and integrate more products.

I always like to ask people what they want to see from PowerCLI next and for a long time now people have been talking to me about vROPs and telling me their use cases of being able to use the rich dataset and analytics provided by vROPs to make decisions and take further action with PowerCLI, something as simple as monitoring a web server to know when it is under duress and provision many more based on these statics all the way to being able to take action on storage systems by monitoring the workload over time.  The use cases are endless and now achievable by the latest version of PowerCLI.  More on this to come in a future post but lets just say I am excited to see what the awesome PowerCLI community does here.

There is so much to talk about in this release, I wanted to give you an overview in this post and then dive deeper into some of the key features in the future.

What’s New?

More Module Enhancements

The community made it clear that we had to move to modules, and whilst we are still getting there, in this release we made even more module enhancements, both to the core distribution model of PowerCLI cmdlets and also converting more of our code base from snapins to modules. In this version the License snap-in has been converted to a PowerShell module. In the new release the PowerCLI Modules have also been moved to the System PSModulePath allowing all users of a machine to access them once installed.

vROPS Support

As briefly mentioned above, a new module and cmdlets have been added to this release to allow access to vRealize Operations, access to the entire public API is available from the $global:DefaultOMServers variable using the ExtensionData property and full cmdlets have been included for the most used features, this gives us a good mix of fully functional easy to use cmdlets and yet the access for advanced users to be able to access the entire API through the ExtensionData property to create their own functions to expose anything to automate vROPs.  The following cmdlets were added for using with vROPs:

  • Connection: Connect-OMServer , Disconnect-OMServer
  • Alerts: Get-OMAlert, Get-OMAlertDefinition, Get-OMAlertSubType, Get-OMAlertType, Set-OMAlert
  • Recommendations: Get-OMRecommendation
  • Resources: Get-OMResource
  • Statistics: Get-OMStat, Get-OMStatKey
  • User Management: Get-OMUser

Update Manager

PowerCLI for Update Manager has always been available as a separate downloadable installer but it was hard to work with, you needed to work out which version of Update Manager you had installed on the server and install the exact version of PowerCLI cmdlets to work with it, this was obviously a pain when using multiple versions of vCenter or when trying to manage them from one machine.  In this version PowerCLI for vSphere Update Manager is no longer a separate downloadable component or installer and is now included in the core PowerCLI installer, it is selected by default during the PowerCLI install wizard which allows for simpler and quicker deployment and management of VMware products through PowerCLI. Enhancements have also been made to ensure a better backwards compatibility experience of this module and now supports versions of vSphere Update Manager all they back to 5.5.

vCloud Air

In the previous release we introduced PowerCLI for vCloud Air, allowing you to connect to your dedicated resources you have purchased and transfer your automation skillset into the cloud.  In this release you can now also connect to and manage vCloud Air On-Demand (vCA) instances with the –VCA parameter added to the Connect-PIServer and the new Get-PIComputeInstance cmdlet to list all available compute instances. Existing cmdlets for managing vCloud Director and vCloud Air can be used to work with vCloud Air On-Demand where applicable. Additional to these enhancements a new cmdlet has been added to make it easier and enhance the ability to work with OrgVDC Networks called Get-OrgVdcNetwork.

ESXi Host Hardware

This feature was asked for in the PowerCLI Communities, this is just one of the places we monitor to work out what our future releases look like.  New cmdlets have been added to work with ESXi host hardware, these cmdlets give the ability to interrogate your ESXi hosts and provide core system and hardware information.

Two new cmdlets have been added to work with this area:

  • Get-VMHostHardware lists host information
  • Get-VMHostPCIDevice lists all PCI Devices


Over the last number of releases we keep making enhancements to the storage cmdlets, with VSAN, IO Filters and now a number of enhancements have been made to the storage module introducing new cmdlets for working with VMware vSphere® API for Storage Awareness (VASA), NFS 4.1 and updated vSphere API for IO Filtering (VAIO) cmdlets.

The following new additional cmdlets are now available:

  • New VASA Cmdlets : New-VasaProvider, Remove-VasaProvider, Get-VasaProvider and Get-VasaStorageArray
  • New NFS Cmdlets: New-NfsUser, Remove-NfsUser, Get-NfsUser and Set-NfsUser
  • Added VAIO filters Cmdlet: Set-VAIOFilter

A pet peeve of mine and others

In previous versions of PowerCLI when you started the interactive shell it would always start PowerCLI in the directory where we installed the components, as I watched people use PowerCLI I would see them run a CD\ to get back to the root of the C: or they would use it from the install directory and often their commands would line wrap making it slightly harder to read, a small but hugely beneficial change was made in this release, the PowerCLI starting directory has now been changed from the full install path of PowerCLI to the root of the installation drive.

Business as usual

As usual updates have been made for PowerCLI to support the latest versions of the software it works with, in this case Site Recovery Manager (SRM) was updated to 6.1 and additional functionality has been added to discover SRM servers when they are deployed in a “shared recovery model” and support has been added for the vCloud Director 8.0 features which are provided by the backwards compatibility agreement of the VCD API.  All this and many more bug fixes and speed enhancements.

What an awesome release!

VMworld 2015–San Francisco–PowerCLI Session

Firstly, I want to say I had a blast at VMworld SFO this year, it was a fantastic show and it really felt like everyone was buzzing with excitement and interest in VMware, the announcements, the partners and just about everything else that was going on.  I think this may be one of my favorite years to date.


On top of the general excitement there was of course the awesome group discussions, meet the experts, sessions and customer meetings which I took part in, I was lucky enough to present on some awesome topics this year, the normal PowerCLI deep dive I give with Luc (see below) and also a fantastic new technology called Instant Clone (AKA VMfork). The instant clone presentation is not yet available but for those who are into PowerCLI I wanted to let you know that Luc and my session was made available for everyone to view via PowerCLI, including the information we gave on best practices and also a technical preview of PowerCLI.


If you are going to VMworld Barcelona do not worry, we are already adjusting our session to be even better with more best practices and even more information on the awesomeness of PowerCLI.  Well worth attending and watching this as well.


Creating re-usable PowerCLI functions with “Onyx for the Web Client”

Onyx is a tool I have been using for years, it’s a tool that sat between the vSphere C# Client or Windows Client and the vCenter server and intercepted the SOAP calls, it would inspect these SOAP calls and convert them into PowerCLI code.  With the recent move away from the C# Client there is an obvious reason why the original Onyx Fling would not work anymore, its not like you can put it in between the web client and the vCenter service is it ?!

This tool was always a life saver for me as I’m not one to read API documentation, it was always a way to not only work out the code for me to alter and reuse but it was a great way for me to work out how VMware would do something, there is often multiple ways you can code something and if you can see what the C# client was doing to perform an action then that had to be a great place to start.

So up until now it has always been for the C# client, well today all that changes, just released is “Onyx for the Web Client” and it is awesome!

Firstly I want to thank the engineer who worked on it, Atanas Atanasov is a member of the PowerCLI team and was fantastic throughout the project taking feedback from myself and the internal testers at VMware (You know who you are and thanks!) and turning it around very fast to produce the end result which works fantastically.

So how does it work?

There are already some great blog posts out there on the official PowerCLI Blog, on Luc’s Site, Jonathans Site and on Roberts site which go into some detail so I thought I would do a quick video to show you how I like to use it.

In the video below I show how I do not know how to automate an advanced setting of a VM, I show how easy it is to record the action of changing that setting, take the code that the fling produces and then use it to firstly change a single VM to a different setting and then how easy it is to turn this into a function that can be used on all VMs in the environment.  This shows how we can create repeatable code that can be used (and shared) to achieve the task we need all with little knowledge of the API.

Download it now!

Make sure you download and install the fling in your test environment from here.

Watch how to use the fling

PowerCLI 6.0 and vCloud Air

One of the great enhancements in the recently released PowerCLI 6.0 is the ability to connect to vCloud Air and vCloud Air Networks, Massimo has already started doing a great write-up on these over at the vCloud Air Blog here.

So why is this a great enhancement?  Well any new area that supports PowerCLI or PowerShell is a great enhancement to me, I mean being able to use PowerCLI to take your automation one step further is always a bonus!  I love the fact that we can now from one shell manage our vSphere environments and our vCloud Air environments for troubleshooting, reporting, provisioning and general automation.  This also goes along with VMware’s key focus of being able to use the same tools to seamlessly extend your datacenter into the cloud by allowing management with the same tools you use to manage your vSphere environment.  On top of this, the ability to manipulate data in both areas and integrate scripts between your on-premises datacenter and your vCloud Air datacenter opens up some great possibilities, imagine being able to automatically spin up new VMs in the cloud when a script works out you need more resources and automatically adding and removing these to a load balancer etc. True hybrid computing!


Anyway, I could come up with use cases for this all day but lets get down to business and explain how to get started, firstly, read Massimo’s great posts here, secondly lets talk about connecting, there are a couple of tricks I have been using for a while now in vSphere that are transferable skills and also work in the vCloud Air environment that make it more convenient to use.

Connecting to vCloud Air with Username and Password

Firstly its easy to connect to vCloud Air and specify your username and password, this would look like the following:


The first thing you will notice is that we didn’t specify a server to connect to, with the Connect-PIServer cmdlet if no server is specified it uses the default of vchs.vmware.com, one less parameter to specify but what id I don’t want to give my username and password as part of the script?  What if I am giving a demo and I don’t want people to see my password?

Connecting to vCloud Air with interactive prompt

If we want to specify a username and password interactively we can just use Connect-PIServer, this is assuming you have not stored credentials in the VICredentialStore, which we will cover next.


Storing your credentials

This is the method I use the most, with this method I can have a highly secure random password and not need to remember it to connect to vCloud Air, this uses the same method of saving credentials that we use for vSphere environments and even the same secure file.  There are a couple of ways we can do this, the first is with the –SaveCredntials parameter as below:


Or use the New-VICredentialStoreItem cmdlet to create a credential item for vchs.vmware.com


Once you have the credentials stored you can manage them with the Set and Remove –VICredentialStoreItem cmdlets.

Now this has been done if we do not specify a credential it will check the VICredentialStore for credentials and use these so connecting to vCloud Air now becomes a single cmdlet:


Listing the Datacenters and Connecting

Now we have made the initial connection to vCloud Air we can easily list the datacenters we have access to and connect to them, firstly lets list the vCloud Air Datacenters with Get-PIDatacenter and then connect to them with Connect-PIDatacenter (which is actually an alias to the Connect-CIServer cmdlet).


Now you have some tips and can see how easy it is to connect to vCloud Air, in future posts I will make use of this connection to start automating vCloud Air and providing PowerCLI enabled resources to use with vCloud Air.