Category Archives: vCloud Air

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

Storage

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!

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:

image

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.

image

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:

image

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

image

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:

image

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).

image

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.

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.

image

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.

image

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.

image

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:

image

image

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 (
		[Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
		$CIVM
	)
	Process {
		foreach ($VM in $CIVM) {
			If ($VM.Status -ne "PoweredOn") {
				Write-Host "$VM must be Powered On to retrieve metrics"
				exit
			} Else {
				$Metrics = $CIVM.ExtensionData.GetMetricsCurrent()
				$metrics.Metric
			}
		}
	}
}

Function Get-CIVMHistoricalMetric {
	Param (
		[Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
		$CIVM
	)
	Process {
		foreach ($VM in $CIVM) {
			If ($VM.Status -ne "PoweredOn") {
				Write-Host "$VM must be Powered On to retrieve metrics"
				exit
			} Else {
				$Metrics = $CIVM.ExtensionData.GetMetricsHistoric()
				$metrics.MetricSeries
			}
		}
	}
}

# 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
    }
}