Tag Archives: VMware

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

VMware Flings – The inside story

Recently I was asked to participate in a video where I spoke about the recent Onyx For Web Client fling, this was the winner of the Fling contest held in 2015 and produced and released a while back, more information on the fling and how to use it can be found here, and an informational video can be seen at the end of this post.

As part of the fling I was asked some questions on how it was achieved and what flings take to produce at VMware, I have always liked the idea of flings and fully support a number of flings from VMware both internally to the company and externally, as an addition to the video I thought I would also share the answers to the questions I was asked and give you an insight on what it takes to get a fling out and what it means to the development staff at VMware.  Something I would highly recommend in any company to help create and spread innovation throughout the products.

Onyx For the Web Client was certainly close to my heart, being able to give developers and system administrators a record and show feature that allows them to investigate our APIs and learn more is always a good thing.

Find below some Q&A on the fling:

How did you and your team bring the concept from vision to reality?

When someone from the CTO office calls your phone, you answer! But honestly, we already had seen the value and the tremendous following with the old version of Onyx and were aware of the limitations it had, specifically when moving to the web client.  We had already been looking at a web client version of Onyx so when this item won the fling contest we jumped at the chance to be involved.

As a customer I used the original version of Onyx on a weekly basis, the value of being able to automate your infrastructure is huge and if you can find out how VMware does a particular task and convert that to code it doesn’t take much to include it in your custom automation solution and prevent yet another manual task, after all isn’t this the promise of the SDDC J

Being the Product Manager of the PowerCLI team all I needed to do was share the vision with an eager team member, in this case it was Atanas Atanasov, a forward thinking developer in the PowerCLI team, someone who is keen to make an impact and provide the best solution for our customers.  He took some original work that had already been started as part of an intern project and polished it up, added features and ran through the entire development and internal feedback process to produce an awesome fling!

Innovation is hard to manufacture. How did your team at VMware collaborate to innovate in the context of this project?

Innovation in my mind is coming up with a unique way to solve an important customer issue, this is exactly what we did in this case.

When moving towards an automated datacenter, VMware customers need all the help they can get to quickly move from manual tasks to automated tasks and the most popular method of doing this at the moment is PowerCLI, this fling helps our customers understand exactly what happens “under the covers” and replicate this in their scripts.

How does the VMware leadership team help support innovation within the company? How did this affect the development of the Onyx for the Web Client Fling?

The VMware leadership team were fully supportive.  Flings are often worked on in the developers spare time at VMware and I can tell you as the PM for PowerCLI we do not give the developers any spare time!  The VMware leadership team helped me to bring incentives to the engineer, in this case a fully endorsed trip to VMworld where he could share his hard work with the customers that he has helped in producing this very fling.  Atanas and I were able to stand on the Office of the CTO booth talking about the fling and helping customers with automation. It was great to receive their direct feedback and watch their faces when they saw it in action and how much time it would save them.

What’s the reaction been to the Fling since its release?

WOW! The community for PowerCLI and automation was abuzz with the news of this fling, I lost count of the social media comments and blog posts which called this out as an amazing achievement from VMware and a great help to our customers.   When you have a good solution that customers see the value in it is a great day to be a Product Manager at VMware!

Besides this Fling, what’s your favorite Fling?

There are many amazing flings on the flings site, it’s hard to choose just one.  I guess I would need to stay on the automation theme though.

PowerActions is probably my favorite fling, this is kind of the reverse of “Onyx for the web client”, it gives our customers a way to feed their automation back into the web client and perform custom scripted reports and actions on the items in the web client.  Essentially it allows our customers to customize the GUI and gives them a way to perform automated tasks in their day to day console.  Not only this but also share the wealth of expertise that the senior automation engineers have by allowing them to create custom actions for everyone who uses the web client.

Together with “Onyx for the web client” I believe PowerActions is an amazing solution for the automated Software Defined Datacenter.

More Information

Make sure you check out the VMware RADIUS site here for more information on this and watch the video below:

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

Horizon Mirage joins the PowerCLI club

VMware Horizon Mirage is a product in VMware’s EUC range of products that manage images across physical desktops and point of service devices. It uses something called layers to simplify OS and application rollouts. With Mirage, devices are separated into logical layers that can be controlled by the admin or end users. Admins can streamline OS and application layer updates, and end users can keep their personalized settings. Horizon Mirage enables quick OS updates and migrations, application upgrades, and hardware upgrades. Admins can also quickly enroll new PCs with bare metal provisioning.

This has historically been managed via a MMC style console and recently a web interface but new to this product from VMware Horizon Mirage 5.1 is its integration into PowerCLI and the ability of PowerCLI Cmdlets.  The Cmdlets are installed where you would install the Mirage Management Console, normally this is on the Administrators workstation.  Once installed you can connect to the Mirage Server and use the cmdlets to work with Mirage.

Download Mirage and Mirage PowerCLI here: https://my.vmware.com/web/vmware/details?productId=407&downloadGroup=MIRAGE-510


Name Synopsis
Apply-MirageOsMigration This cmdlet applies download only migrations.
Archive-MirageCvd This cmdlet archives the CVD.
Connect-MirageServer This cmdlet configures a connection to the Mirage API server.
Disconnect-MirageServer Disconnects from the Mirage server.
Get-MirageAppLayer This cmdlet returns the app layers from the Mirage system.
Get-MirageBaseLayer This cmdlet returns the base layers from Mirage system.
Get-MirageCvd This cmdlet returns the CVDs from Mirage system.
Get-MirageCvdCollection This cmdlet retrieves the collections from the Mirage system.
Get-MirageOsMigration This cmdlet retrieves the download only migrations from the Mirage system.
Get-MiragePendingDevice This cmdlet retrieves the pending devices from Mirage system.
Get-MiragePolicy This cmdlet retrieves the policies from the Mirage system.
Get-MirageVolume This cmdlet retrieves the volumes from the Mirage system.
New-MirageCvd This cmdlet creates a new CVD with the specified policy and volume in the Mirage sytstem.
New-MirageOsMigration This cmdlet migrates CVD with the specified base layer, app layer and related info in the Mirage system.
Remove-MirageCvd This cmdlet removes the CVD.
Set-MirageCvd This cmdlet updates the CVD with the specified policy.
Sync-MirageCvd This cmdlet synchronizes the CVD’s device information.




Retrieving VM Metrics from vCloud Air

Recently I was working with vCloud air and PowerCLI and was asked if there was a way to retrieve the statics of a VM and export these to get a better idea of the utilization of that VM.

Working with vCloud Air and the API through the PowerCLI cmdlets I was able to use the GetMetricsCurrent() and GetMetricsHistoric() to retrieve both the current VM Metrics and also the historic metrics of a VM.  The type of metrics and their values is described here.

VM Current Metrics

Current metrics are instantaneous values collected at the time the request is processed. The GetMetricsCurrent() method retrieves a list of current metric values, one for each category. I put this into a handy function which can be found at the end of this post, with this function we can pass vCloud AIR VMs into it and retrieve the current metrics.


VM Historic Metrics

Historic metrics are collected and stored for 14 days. A call to the GetMetricsCurrent() method retrieves the past 24 hours of metric history.  again I created a function that allows us to select a VM (or multiple) and get the historic data for this VM.


You will see that this time the method returns a collection of results in the Sample entry, we can then expand this to return the results for the metric over the last 24 hours.


Creating a VM Statistical report

Of course with this being PowerShell we can add value to these results, I mean who wants to look at a long list of numbers, wouldn’t you rather see a pretty graph?  We can easily use Luc’s great Export-XLSX function to export the results for each metric straight into Excel and even create us a nice graph for each statistic:



The Functions

Make sure you download Lucs Export-Xlsx function from here, and below are the functions I used to retrieve this information from vCloud Air.

Function Get-CIVMMetric {
	Param (
	Process {
		foreach ($VM in $CIVM) {
			If ($VM.Status -ne "PoweredOn") {
				Write-Host "$VM must be Powered On to retrieve metrics"
			} Else {
				$Metrics = $CIVM.ExtensionData.GetMetricsCurrent()

Function Get-CIVMHistoricalMetric {
	Param (
	Process {
		foreach ($VM in $CIVM) {
			If ($VM.Status -ne "PoweredOn") {
				Write-Host "$VM must be Powered On to retrieve metrics"
			} Else {
				$Metrics = $CIVM.ExtensionData.GetMetricsHistoric()

# Get the Current Metrics for the VM
Get-CIVM sql-w-01a | Get-CIVMMetric

# List the Available Historical Metrics for the VM
Get-CIVM sql-w-01a | Get-CIVMHistoricalMetric

# Get the CPU Historical Metrics
Get-CIVM sql-w-01a | Get-CIVMHistoricalMetric | Where {$_.Name -eq "cpu.usage.average"} | Select -ExpandProperty Sample

$VMName = "sql-w-01a"
Foreach ($stat in (Get-CIVM $VMName | Get-CIVMHistoricalMetric)){
    Foreach ($Entry in $Stat) {
        $Data = $Entry.Sample | Select Timestamp, @{Name=($Entry.Name);Expression={$_.Value}}
        Export-Xlsx $Data C:\Temp\$VMName.xlsx -WorksheetName ($Entry.Name) -ChartType "xlXYScatterSmooth" -AppendWorksheet

Receiving alerts on if a VM has over a given number of snapshots

Last week I was asked if there was an easy way to get an alert once a VM had over a certain number of snapshots, this is a frequent request as it would seam some backup products like to keep snapshoting VMs and note removing them.

There are several ways this could be kicked off, including setting a vCenter Alarm on snapshots and getting it to run a script but in this case it was simple, they wanted to run a scheduled task once a day and get an email listing the VMs that had over x amount of snapshots and the details about the last one created, of course it was a 5 minute script but I thought I would blog it anyway for others to use if they needed it.  Enjoy


BTW, its also very easy to get this to work with gmail if you use that as your email provider, just replace the Send-EmailMessage line with the below:

$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“my.email@gmail.com”, “mYpa$$w0rd”);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)


Example email



Automated deployment of vCloud Networking and Security 5.5

A while ago I posted a PowerCLI method for deploying vShield 5.0 which can be found here, as mentioned in the comments of that post this did not work for vCNS 5.5, this is because the process of deploying it changed and actually became a lot neater than what it was before.  Before we had to reach inside the guest OS and mess around with configuration files.  In the 5.5 release the vCNS team made some changes to make this easier for people to automatically deploy,


I actually wrote this a while ago and forgot about it until recently when I was asked if it could be done, this was a great reminder for me to post the code for others to use.


You will see in the code that we need to specify some variables at the start of the script, you will see in the code that you need to specify a cluster to deploy vCNS to, as part of this script it automatically picks a random host and a shared datastore which has enough room to deploy the appliance to, this is just an example and can be changed to your requirements as needed – I was just having fun with a kind of automated placement Winking smile

You will need PowerCLI 5.8 R1 for this and don’t forget, once vShield has been deployed you can easily take the configuration further by using the vShield module I created here.   For other examples of deployment scripts for VMware appliances check out the repo here and contribute!

Example output



Automating Tags and Tag Category creation and assignment with PowerCLI

Fimageor a couple of releases now PowerCLI has been able to work with vSphere Tags, A tag is a label that you can apply to objects in the vSphere inventory.

After creating a tag, you can assign that tag to a category. Categories allow you to group related tags together. When you define a category, you can also specify the type of objects to which its tags can be applied to and whether more than one tag in the category can be applied to an object.

For example, if you want to tag your virtual machines by the owner, you can create a category called “Owner” and specify that it applies to virtual machines only and that only a single tag can be applied to a virtual machine at any time. The tags in this category could be Alan, John or Fred etc.

I have had a few people ask me how they can use PowerCLI to work with external systems, CMDBs, databases or even just a CSV file.

One example of this is where a company could have various information about hosts or datastores or virtual machines, like the project that purchased these, a cost code or an owner.  This data is generally stored somewhere else but it would be great to see this information straight in the vSphere Web Client where you manage the objects so that you can instantly contact the owner or work out which project the object is being used for etc.

The below video shows how we can use PowerCLI and this generic script I created to import the data, create the tags and tag categories and assign them to the machines, it uses a csv as input but this could obviously be changed to anything which can be read in PowerShell, like a API, database, application etc etc.

Automating tags and tag categories video

Example Script

This script is the script I created as an example which relates each of the items in the Name column to an object in the inventory then for each of the other column headers it will create a category and then the tags that are under the categories, once this has been done it will apply the tags to the objects in the Name column.

Connect-viserver myvc.corp.local -user administrator@vsphere.local -pass Pa$$w0rd
$CMDBInfo = Import-CSV C:\Software\cmdbinfo.csv

# Get the header names to use as tag category names
$TagCatNames = $cmdbinfo | Get-Member | Where {$_.MemberType -eq "NoteProperty"} | Select -Expand Name

# Create the Tag Category if it doesnt exist
Foreach ($Name in ($TagCatNames | Where {$_ -ne "Name"})) {
    if (-Not (Get-TagCategory $Name -ea SilentlyContinue)) {
        Write-Host "Creating Tag Category $Name"
        New-TagCategory -Name $Name -Description "$Name from CMDB" | Out-Null
        # Create Tags under the Tag Categories
        $UniqueTags = $cmdbinfo | Select -expand $name | Get-Unique
        Foreach ($Tag in $UniqueTags) {
            if (-Not (Get-Tag $Tag -ea SilentlyContinue)) {
                Write-Host "..Creating Tag under $Name of $Tag"
                New-Tag -Name $Tag -Category $name -Description "$Tag from CMDB" | Out-Null
            # Assign the Tags to the VMs/Hosts
            $cmdbinfo | Where {$_.($Name) -eq $Tag} | Foreach {
                Write-Host ".... Assigning $Tag in Category of $Name to $($_.Name)"
                $TagAssignment = Get-Tag -Category $Name -name $Tag
                New-TagAssignment -entity $($_.Name) -Tag $Tagassignment | Out-Null