Home > Blogs > VMware PowerCLI Blog > Tag Archives: PowerShell

Tag Archives: PowerShell

New Release: VMware PowerCLI 11.3.0

Today marks the release of VMware PowerCLI 11.3.0 and this one brings the count up to 732 different cmdlets. The combination of all these cmdlets allow us to manage and automate a majority of the VMware ecosystem! The HCX module receives the bulk of the new cmdlets, however there is also a new cmdlet to interact with the vSphere Storage Policy Based Management (SPBM) APIs. There is a new way to view opaque network types and a high-level method of promoting instant clones to full clones. Last, but certainly not least, this release also includes a handful of updates for reported issues and two deprecations.

PowerCLI 11.3.0 comes with the following updates:

  • Added 22 new cmdlets for HCX and SPBM management
  • Added support for vSphere 6.7 Update 2 to the VMware.VIM module
  • Added support for opaque networks to the Get-VirtualNetwork cmdlet
  • Added support for the creation of additional network adapter types
  • Added support for the high-level promotion of instant clones
  • Updated the handling of a Cluster’s ‘SpbmEnabled’ status
  • Updated the handling of bulk tagging assignments

Let’s take a more in-depth look at some of the updates.

Tag Improvements

vSphere tags are always a popular discussion. Normally, the conversation ends up being about performance. This update, with PowerCLI 11.3, allows us to make use of the backend API where we can perform bulk assignment of tags. This means that the New-TagAssignment cmdlet has been updated to allow for arrays to be passed for either the Entity or Tag properties. In my test environments, I am able to report anywhere from a 12x to 18x improvement in performance. Of course, the performance will vary by environment. The following is an example of running the same set of 100 vSphere tags to a single VM. In PowerCLI 11.3, the task took 1.771 seconds whereas in PowerCLI 11.2, it took 32.495 seconds. That’s a pretty impressive improvement.

Example: Bulk Tag Assignment Operations

For more information about general vSphere tag performance with PowerCLI, check out a recently released blog from the Performance team: Writing Performant Tagging Code

New Cmdlets for HCX

VMware HCX is best thought of as a swiss army knife – a single tool with multiple options to move your workloads in and out of the cloud. The HCX module was introduced just earlier this year, in PowerCLI 11.2.0, as the 21st module for PowerCLI. New in PowerCLI version 11.3.0, the module receives an additional 21 cmdlets to interact with your HCX deployment. A majority of the new cmdlets deal with profiles, which are used as a site’s deployment configurations for items like storage, compute, and networking. There are also new cmdlets to manage the HCX Service Mesh, which is composed of the source and destination sites.

A complete list of the newly added cmdlets:

  • Get/New/Remove/Set-HCXComputeProfile
  • Get-HCXInventoryCompute
  • Get-HCXInventoryDatastore
  • Get-HCXInventoryDVS
  • Get-HCXInventoryNetwork
  • Get-HCXNetworkBacking
  • Get/New/Remove/Set-HCXNetworkProfile
  • Get/New/Remove/Set-HCXServiceMesh
  • Get-HCXStorageProfile
  • New-HCXComputeProfileDVS
  • New-HCXComputeProfileNetwork
  • New-HCXServiceMeshDVS

More information on using the HCX module can be found in the following blog post: Getting Started with the HCX Module

Opaque Network Support

Another improvement to the PowerCLI 11.2 release was the addition of a new object type for opaque networks. These network types are the result of logical switches that have been created in NSX-T. That update allowed us to retrieve these objects through only low-level, direct API access, commands. With PowerCLI 11.3, the Get-VirtualNetwork cmdlet has been updated so we can now view opaque networks with a high-level cmdlet!

An example of using Get-VirtualNetwork to display distributed, opaque, and standard networks:
Example: Showing all types of virtual networks

For some additional information about working with opaque networks in vCenter, see the following blog: Configuring VMs with Opaque Networks

Instant Clone Promotion

Instant Clone is a functionality which has been around VMware in one form or another for quite a while. First discussed as “VMFork”, going back as early as 2014, this allows us to immediately create a child VM based off of a presently powered on VM, which we can then viewe as a cloned VM in vCenter. vSphere 6.7 was the first release to have this available as a public feature, though it was only available through the API. This is where PowerCLI, and specifically version 11.3, comes into play because we can now make use of the Set-VM cmdlet combined with the PromoteDisks parameter against one of the available child VMs to create a fully cloned VM object. The selling point is that afterwards, there is no longer a dependency on that parent VM!

Look for more information about this great new functionality in a future blog post.

SPBM Updates

The last big update we’re going to cover is for those looking to automate the management of vSphere Storage Policy Based Management (SPBM) policies. The first update comes in the form of a new cmdlet named Get-SpbmView. This cmdlet gives us direct access to the available APIs for SPBM. In the example below, we can see the usage of this cmdlet to list out the available services and start to interact with the Replication Manager service to see the available methods.

Example: Get-SpbmView Usage

The other update is to how the Get/Set-SpbmEntityConfiguration cmdlet operates. Both of these cmdlets can now display or modify policies for datastores. However, there is also a deprecation for cluster objects and whether they display an “SpbmEnabled” status. This is due to a change, which happened as of vSphere 6.0, where clusters always have a status of “Enabled.” Here is an example of using the Get-SpbmEntityConfiguration to display information about the specified datastore.

Example: Viewing SPBM Policies for datastores

Summary

The second release of the year is here in the form of PowerCLI 11.3.0. This release adds 22 new cmdlets to help automate workload migrations and granular management of SPBM policies. There are new ways to manage network-based objects, whether those are networks themselves or network adapter types. We can also now upgrade an instant clone to a full clone with an easy to use, high-level cmdlet. Lastly, bulk tag assignment is now a supported mechanism of the New-TagAssignment cmdlet.

For more information on changes made in VMware PowerCLI 11.3.0, including improvements, security enhancements, and deprecated features, see the VMware PowerCLI Change Log. For more information on specific product features, see the VMware PowerCLI 11.3.0 User’s Guide. For more information on specific cmdlets, see the VMware PowerCLI 11.3.0 Cmdlet Reference.

Remember, updating your PowerCLI modules is now as easy as ‘Update-Module VMware.PowerCLI’.
Example: Update-Module -Name VMware.PowerCLI

Let us know in the comments what you’re most excited about!

New Release – DSC Resources for VMware 2.0

The Desired State Configuration (DSC) Resources for VMware was released late last year. This initial release was able to leverage the PowerShell DSC engine in order to declare configurations for a handful of ESXi host settings and a couple vCenter server settings. The response to these resources has been amazing! So amazing that over the last 7 months, there have been 64 issues and 74 pull requests. A result of all of that feedback, input, and code contributions brings us to the next release, version 2.0 of the DSC Resources for VMware!

The DSC Resources for VMware version 2.0 contains a number of new resources, lots of improvements, and a new way to access them. First and foremost, as requested, these resources are now available on the PowerShell Gallery! There are also a number of examples which have been added to the repository since the first release. In the root of the repo, there’s an ‘Examples’ folder which contains some examples of combining multiple resources into a single configuration. Then, within the resource itself, there’s a folder by the name of ‘Configurations’. This folder has example configurations of using these resources with configuration management utilities like Ansible, Chef, and Puppet. Lastly, there are 14 new resources for us to use!

Let’s walk through some of the new resources.

New Resources

These newly added resources can be easily categorized into the following buckets: Inventory, vSphere Standard Switch (vSS), and VMHost.

The new Inventory resources, which allow us to manage the existence of these object types, are:

  • Cluster
  • HACluster
  • DRSCluster
  • DatacenterFolder
  • Datacenter
  • Folder

The following is an example of using the Folder resource to manage a VM based folder, named Management, along with a folder nested in the first folder:

The new vSS resources, which allow us to manage a VMHost’s vSS configuration, are:

  • VMHostVss
  • VMHostVssBridge
  • VMHostVssSecurity
  • VMHostVssShaping
  • VMHostVssTeaming

The following is an example of using the VMHostVss resource to manage a vSS on a particular VMHost:

The new VMHost resources, which have been added to the already existing set of resources that manage VMHosts, are:

  • VMHostService
  • VMHostSettings
  • VMHostSyslog
  • VMHostAccount

The following is an example of using the VMHostService resource to manage an ESXi host’s SSH service to ensure it is running and the policy is set to automatic:

Here’s a demo which combines a number of the new resources for the following configuration:
Datacenter: DemoLab
Folder Structures:
Development
- Linux
- Windows
Management
- Linux
- Windows
- VMware
Production
- Linux
- Windows

PowerCLI DSC v2 Resources Demo

Summary

The DSC Resources for VMware have only been available for a short period of time, however they have made a tremendous impact! Over the last 7 months, there have been 64 issues and 74 pull requests to the GitHub repository. Today, we’re taking the culmination of that input and releasing the 2.0 version of these resources. This adds an additional 14 resources, a number of functionality improvements, and they have been added to the PowerShell Gallery!

I also want to say a special thank you to some of our community contributors: Luc Dekens, for his immense contributions to this release including having a hand in at least 8 of the new resources as well as Brett Johnson and Markus Fischbacher for their contributions as well!

To get started, it is now as simple to install as:

Demo: DSC Resource Installation

For more information on this release, see the latest release page on the DSC Resources for VMware GitHub page.

Let us know in the comments how you’re using these in your environment and what resources you’re looking for next!

Moving a Datastore Cluster to a New Folder

We often get lots of interesting requests about figuring out how to automate something. The latest request was about how to move a datastore cluster between folders. This is the type of automation action which probably doesn’t need to be used all that often and is more aesthetic in nature than anything else. However, the interesting part is that, this request came from someone that found out they couldn’t perform the action in the UI. So, PowerCLI to the rescue!

Move-DatastoreCluster

PowerCLI doesn’t have a high-level cmdlet for this action, so we’ll be creating our own. To perform this action, we’ll be using a method that’s available in the vSphere API known as “MoveIntoFolder.” We can see some additional information about this method in the VMware Code API Explorer: MoveIntoFolder Method

I have created and shared a script on the PowerCLI Community repository and the VMware Code Sample Exchange which takes that “MoveToFolder” and wraps it in an advanced function we can call with: Move-DatastoreCluster

Example Usage

The script will need to be, what’s known as, dot sourced so that the advanced function is available in our current PowerShell session. From that point we will use the ‘DatastoreCluster’ parameter to pass a Datastore Cluster and the ‘Destination’ parameter to pass a folder.

Putting this altogether looks a bit like the following:
Move-DatastoreCluster Example Code

Summary

PowerCLI is a great tool to use when automating VMware environments. In the case of Datastore Clusters, we can actually use PowerCLI to perform tasks which aren’t available in the vSphere Client! The Move-DatastoreCluster script has been shared and presents an advanced function, of the same name, which allows us to move Datastore Clusters between the available folders.

If this is a function you’d like to see added to PowerCLI, head out to the public feature request site and upvote the following idea: Enhancement for moving inventory items Datastore Cluster

Obtaining Specific PowerCLI Versions from the PowerShell Gallery

The recommendation is to always be on the latest and greatest version of PowerCLI. However, whether it be for testing and validation or to possibly workaround an issue, there are instances where you may need to use an older version.

The PowerShell Gallery has the potential to make this process incredibly easy when using the RequiredVersion parameter for both Install-Module and Save-Module. These cmdlets download and/or install the indicated module at the specified version. The issue, especially with PowerCLI, comes in how the dependent modules are handled. This is because, in most cases, the module dependencies are specified to be obtained at a particular level or newer.

Example PowerCLI Dependency Listing:
PowerCLI Module Dependencies

This means if you want to download PowerCLI 6.5.4 with either the Install-Module or Save-Module cmdlets, the end result will not actually give you the requested version of PowerCLI. You would only receive the top-level VMware.PowerCLI module at version 6.5.4. All of the module dependencies which make up the PowerCLI 6.5.4 release will be at the latest and greatest version.

So, how can we properly download prior versions of PowerCLI?

Introducing Save-PowerCLI

Dimitar Milov, a PowerCLI engineer, came up with a function to address the issue and shared it in the comments on the PowerShell Gallery page for the VMware.PowerCLI module. From that point, I added a couple new features and shared it in both the PowerCLI Community repository and the VMware Code Sample Exchange.

Save-PowerCLI In Action

Demo: Save-PowerCLI Usage

Save-PowerCLI Code

Known Issues

There are a couple issues I’ve noticed when testing this against various versions of PowerShell.

  • Older versions of PowerShellGet (Example: 1.0.0.1) will fail because it can’t handle the formatting of one specific PowerCLI version.
    • Workaround: Update PowerShellGet. Example: Install-Module -Name PowerShellGet -Force
  • Newly released PowerCLI modules can be found downloaded, even if they did not exist at the time of the specific version release.

Summary

We always recommend how everyone should be on the latest and greatest version of PowerCLI. However, we also recognize that isn’t always possible. Whether it be for testing and validation, working around known issues, and so forth, there are reasons and needs to be able to obtain prior versions of PowerCLI from the PowerShell Gallery. The Save-PowerCLI function can streamline the download process of retrieving those specific versions of PowerCLI.

Let us know what you think of this function in the comments!

New Community Module for Tag Management

vSphere tags, in my opinion, are one the unsung heroes when it comes to VMware environment management. They’re extremely versatile. They can be used as labels. They can be used to group similar objects and/or multiple object types together. They can be used to apply policies. There are third party products also using them. I’ve seen lots of companies use them in lots of creative ways. However, automating their usage can be slow in some environments and not available at all in larger environments.

There’s a new module in the PowerCLI Community Repository to help against some of those issues. This new module, named VMware.Community.CISTag, makes use of the vSphere REST API to manage tags in a more performant manner.

The VMware.Community.CISTag module includes the following advanced functions:

Function Name Synopsis
Get-CISTag Gathers tag information from the CIS REST API endpoint
Get-CISTagCategory Gathers tag category information from the CIS REST API endpoint
Get-CISTagAssignment Displays a list of the tag assignments from the CIS REST API endpoint
New-CISTag Creates a new tag from the CIS REST API endpoint
New-CISTagCategory Creates a new tag category from the CIS REST API endpoint
New-CISTagAssignment Creates new tag assignments from the CIS REST API endpoint
Remove-CISTag Removes a tag from the CIS REST API endpoint
Remove-CISTagCategory Removes tag category information from the CIS REST API endpoint
Remove-CISTagAssignment Removes tag assignments from the CIS REST API endpoint

There are also some requirements that are needed in order for this module to work:

  • vCenter 6.0 or newer
  • PowerCLI 6.5.3 or newer
  • Active vCenter CIS service connection, using Connect-CISServer
  • Preferred: Active vCenter connection, using Connect-VIServer

Let’s take a quick look at how to get started using this module.

Accessing the Module

There are a couple ways to get access to this great module, all of which go through the PowerCLI Community Repository. One of the easiest ways is to load up the repository’s page, click on the green ‘Clone or download’ button, then clicking on ‘Download ZIP’. This downloads the entire contents of the repository to your local system.

Download PowerCLI Community Repository to Local System

Once the download is complete, unzip the files and browse to the ‘Modules’ directory. We are now going to copy the VMware.Community.CISTag folder and paste it in one of the directories that are listed in the PSModulePath variable. Doing this allows the module to be available for automatic importing by your PowerShell session!

By default, the PSModulePath variable contains the following directories:

  • $home\Documents\WindowsPowerShell\Modules
  • $pshome\Modules

In my environment, I have placed the module in the first of the above options. This is also where my PowerCLI modules are available.

Module Overview

The functions are written in a very similar format to the existing PowerCLI Tag cmdlets. If you’ve ever used the existing tag cmdlets, these operate in a very similar fashion and offer a very similar response. However, there are some changes that you should be aware of. The PowerCLI Tag cmdlets generally work with objects, whereas these functions work with names or IDs. This means you should test these new functions thoroughly before updating any existing scripts and/or workflows. Making use of Get-Help will greatly aide in the transition.

Overall, I noticed some good performance increases as well.

Example: Comparing an environment with 400 tags assigned, saw an improvement of roughly 25%
Performance test of listing tag assignments

There are some other features that have been added which can be used to achieve even more performance. The first, by using an object’s ID whenever possible. Most of the functions also feature TagId and ObjectId which can be referenced instead of the name parameters. This helps by cutting down on the amount of additional calls which are being made to translate a name into an ID value.

The second way to see even more performance improvement is through the usage of bulk actions. This applies specifically to the TagAssignment functions. The underlying API method allows multiple tags to be assigned or removed from a single object or a single tag can be assigned or removed from multiple objects. Therefore the New-CISTagAssignment and Remove-CISTagAssignment functions accept strings or arrays for Tag or Entity properties. There’s also the ability to further speed up the process by using object IDs too.

Example: Comparing the difference between the bulk assignment of a single tag against multiple VMs. Top example is name based, the bottom example is ID based.
Bulk action performance results

The last big note on improvements for this module, I have yet to run into any timeout issues, maximum results errors, and so forth.

Example: Comparing an environment with 1400 tags assigned, where the Get-TagAssignment cmdlet fails while the Get-CISTagAssignment succeeds
Example comparison with 1400 tags assigned

Summary

The CISTag module is a great new resource for anyone automating tag usage within their vSphere environment. By switching to the tagging methods available in the REST API, we’ve seen performance improvements, the ability to overcome timeout errors, and more!

Head out to the PowerCLI Community Repository, download it, and let us know in the comments how you’re putting it to use in your environment!

Getting Started with Desired State Configuration Resources for VMware

Today, we are happy to announce a brand-new and open-sourced way to manage your vSphere environment. The Desired State Configuration (DSC) Resources for VMware allows partners, automation engineers, DevOps teams, and system administrators a new way to apply standard configuration management processes through PowerShell DSC and PowerCLI!

Let’s take a walk through how we can get started using these DSC resources and apply our first configuration!

Desired State Configuration Resources for VMware Overview

PowerShell DSC has been out for a while, since Windows Server 2012 R2 as a matter of fact. To summarize in a single sentence: PowerShell DSC can manage and monitor a system’s configuration based on what’s known as configuration files, which happen to be written as PowerShell code. This is all made possible thanks to the Local Configuration Manager (LCM). LCM is the “engine” running locally on each of the target nodes that takes the configuration file, interprets it, and applies all the configured parts. These parts include a system’s configuration, in what manner the configuration is refreshed, and how often it is refreshed, just to name a few.

The above is important because the DSC Resources for VMware operate a little differently than a standard DSC configuration. The DSC Resources for VMware make use of a proxy LCM host. This is because the LCM cannot run on the VCSA (both vCenter and PSC based appliances) nor can it run on ESXi hosts. An important note about this proxy LCM host, it has to be Windows PowerShell based. Furthermore, only PowerShell 5.1 and PowerCLI 10.1.1 or newer will be supported.

Desired State Configuration Resources for VMware

This first release of the DSC Resources for VMware will be able to manage a couple different areas for both vCenter and ESXi hosts. They are as follows:

  • vCenterStatistics
    • Level
    • PeriodLength
  • vCenterSettings
    • EventMaxAge
    • TaskMaxAge
    • Logging Level
  • VMHostNtpSettings
    • NTP Server
    • NTPD Service Policy
  • VMHostDnsSettings
    • HostName
    • DomainName
    • Address
  • VMHostSatpClaimRule
    • RuleName
    • Transport
    • Description
  • VMHostTpsSettings
    • ShareScanTime
    • ShareForceSalting

Installation Overview

We now know what it is and what it can do, how about the installation? On the designated proxy LCM system, we will want to download the module from GitHub and make it available in one of our designated PSModulePath directories. The zip file is available through the following link: Desired State Configuration Resources for VMware

Here’s some code that can streamline the download and initialization process:

After we have installed the module we should be able to list the newly acquired module and import it into our active PowerShell Session:

Example: Importing the VMware.vSphereDSC Module

We can also verify the DSC resources we have available:

Example: Output of available DSC Resources

Next, we need to make sure the proxy LCM system can understand the DSC configuration files. This is done through the Windows Remote Management service. We can setup the WinRM service or verify that the WinRM service is setup with the following code:

In my environment, this system already had WinRM setup so I received the following message:
Example: Windows Remote Management Configuration

We should now be all set to start setting up DSC resources in our environment!

Managing an ESXi Host’s NTP

The DSC Resources for VMware repository has some pre-created configuration files which can be sourced to create the MOF file. The MOF file, which stands for Managed Object Format, is the output from a configuration file which has been compiled by the LCM. These configuration files are located in the repo at the following location: \Source\VMware.vSphereDSC\Configurations In my environment, I’ve created my own fork of the repository and cloned it to my local system where I’ll be referencing the files.

In our example, we’re going to setup DSC to manage an ESXi host’s NTP configuration. We can see some parameters and some settings by opening the VMHostNtpSettings_Config.ps1 file that’s located in the ESXiConfigs directory.

Input Type Input Name Input Description
Parameter Name Resource Name
Server Server Host Name
User ESXi host username
Password ESXi host password
Setting NtpServer NTP server/s the host will use
NtpServicePolicy Status for the NTPD service

For my lab environment, I’m going to update the NtpServer values and accept the service policy setting of ‘automatic’. I’m also going to apply this configuration at the ESXi host level, so my host name and server name will match.

We can do this with the following commands:

As part of the output, we should see the following MOF file having been created:
Example: Configuring and creating MOF file

We can then test the MOF file against our host with the following command:

Added to the output, I have also included another PowerShell session which is polling the host for the current NTP server/s and service policy:
Example: Pre-DSC Configuration

In the above example, notice the ‘InDesiredState’ property with a value of False.

Now, we’re ready to start applying our configuration. We do this with the following command:

After a few moments, we’re ready to check the current DSC configuration with the following command:

Again, I’ve added a second PowerShell session to show the current status of the host:
Example: Post DSC Configuration Status

For reference, this is the code I’m running to show the current status of the host’s NTP configuration:

In some later blog posts, we’ll take a look at some of the other areas of this module including applying configurations to multiple hosts, applying vCenter settings, applying values to multiple hosts in a vCenter, and some ways to apply better security practices to both the credentials and the MOF.

Summary

PowerCLI is back with a brand-new feature, Desired State Configuration Resources for VMware! These resources allow PowerCLI to make use of PowerShell DSC to define the configuration of a desired node. The DSC Resources for VMware can define ESXi host settings such as NTP servers, DNS servers, and TPS share scan times. We can also define vCenter settings such as statistics level and logging level. As an additional benefit, these resources are also open-source and community contributions are absolutely welcome!

Check out the Desired State Configuration Resources for VMware on GitHub and let us know what you’re looking forward to using DSC on most in your vSphere environment!

Discovering VMs with Specific VMware Tools Versions

A recent knowledge base (KB) article was released regarding an issue impacting a specific version of VMware Tools. The KB in question is 57796, which describes the possibility of a guest level network connectivity issues or even a purple diagnostic screen (PSOD).

Before getting to the discovery process, I want to cover some of the specifics for this KB. I do this because we’re going to need to be aware of these as we build out our one-liners and the subsequent reporting script.

The issue in the KB may be found when combined with the following:

  • VMware Tools version 10.3.0
  • ESXi 6.5 Hosts
  • VM Hardware 13
  • Windows Server 2012 or newer -OR- Windows 8 or newer

Now that we know what we’re looking for, lets cover some methods we’ll be using to make this easier.

Properties, Hash Tables, and More

Since we’re going to be focused on VMs, we’ll be making use of the Get-VM cmdlet. However, the information we need isn’t available as part of the cmdlet’s default response. We’ll need to choose specific VM properties to display.

Discovering those properties can be done in a couple different ways. If we just want to find out what properties are available and how they’re defined, we can use the Get-Member cmdlet. If we want to find out the values for all of those properties, we can use the Format-Table cmdlet. Both of these cmdlets can be used in the same way, by using the Get-VM cmdlet and passing the output to the desired cmdlet with a pipeline.

Example Code:
Show Properties for Virtual Machine Objects

In this case we’re going to be referencing the ‘Name’ property and an additional property which is available as part of the listed ‘Guest’ property, which is actually defined as an object. The property we’re looking for in the Guest object is named ‘ToolsVersion’.

We can output these specific properties using the Select-Object cmdlet. In order to properly display the ‘ToolsVersion’ property, we’ll be using a hash table to create a calculated property. The hash table is created with an ampersand and curly brackets. We can establish the calculated property with ‘name’ and ‘expression’ values.

Listing VMs and their VM Tools Versions

First things first, let’s figure out how to display our VMs’ names and their VM Tools version using the Select-Object cmdlet and a calculated property for the Tools Version.

Example Code:

PowerCLI - Get VMs and list Name and Tools Version

Listing VM Specific Information from the KB

In the example above, we can see there’s one particular VM which may be impacted by the KB. So, the next step is to obtain the rest of the information about each of the VMs.

We’ve already obtained the VM’s name and VMware Tools version properties. Now we need to figure out the ESXi host version, VM Hardware version, and what OS is in use.

The ESXi host version can be found using the VMHost property. This property returns the full ESXi host object. Since we’re working with the full object, we can return the ‘Version’ property by way of the calculated property method we used previously.

The VM Hardware version can be found by referencing the ‘HardwareVersion’ property.

The last property we’re interested in is the OS type. This too is available as a sub-property to ‘Guest’. There’s a couple to choose from, but for this example we’ll start with the ‘GuestFamily’ property.

Example Code:

Obtain requisite information for each VM per the KB

Listing Only Applicable VMs

For our last example, let’s take this process a step further and display only the susceptible VMs.

We’ll do this with the Where-Object cmdlet. We’ll use this cmdlet, in combination with a script block, to validate that each of those properties match those items listed in the KB.

We’ll be validating the following properties:

ToolsVersion 10.3.0
VMHostVersion 6.5.0
HardwareVersion vmx-13
GuestFamily windowsGuest

Example Code:

View only potentially impacted VMs

Summary

Knowledge Base article 57796 details a specific issue which has the potential to impact environments. We can use PowerCLI to easily poll our environment to obtain, and even isolate, the specific VMs which may be impacted.

Let us know in the comments how you’re building on what’s available here to create reports and even remediations!

PowerCLI at VMworld US 2018

VMworld 2018 Banner

It’s August and that means VMworld is right around the corner! Last year, we had an unprecedented amount of PowerCLI and automation-based sessions and that trend has continued this year! There are more sessions, a re-vamped PowerCLI Hands-On-Lab, not one but two expert-led PowerCLI Hands-On Lab time slots, a Hackathon training session, and there are more vBrownBag & VMware {code} Power sessions than I can count! If you haven’t already registered, the time is quickly ticking away!

Make sure to add the following sessions to your schedule and catch up with the PowerCLI team and the amazing PowerCLI community members!

Sessions

Session: DEV3504BU – Development at VMware: A Look at How PowerCLI Has Evolved Over the Years
Date: Monday, Aug 27, 4:00 p.m. – 5:00 p.m.
Speakers: Kamen Nikolov & Kyle Ruddy
Kamen and Kyle will give attendees a behind the scenes look into the PowerCLI development process and the many ways PowerCLI has evolved over the last 10+ years.

Session: VIN2661BU – Start Automating All The Things with PowerCLI
Date: Tuesday, Aug 28, 2:00 p.m. – 3:00 p.m.
Speakers: Seth Crosby & Kyle Ruddy
Seth and Kyle will help attendees get more comfortable with using automation tools like PowerShell and PowerCLI. This session will feature an introductory overview, followed by several examples which attendees can start using in their environments immediately!

Session: VIN1709BU – Mac and Linux Users, Don’t Despair: PowerCLI Is There!
Date: Tuesday, Aug 28, 3:30 p.m. – 4:30 p.m.
Speakers: Luc Dekens & Alan Renouf
Luc and Alan will discuss how PowerShell and PowerCLI have gone multi-platform, what impact that has on your environment and your existing code, plus some keys to success.

Session: HCI2522BU – Getting Started with vSAN Automation
Date: Tuesday, Aug 28, 5:00 p.m. – 6:00 p.m.
Speakers: Alan Renouf & William Lam
Alan and William show attendess how to get started automating all the aspects of vSAN with tools such as PowerCLI and the vSAN management SDKs.

Session: VIN1992BU – A Deep(er) Dive with PowerCLI 10
Date: Wednesday, Aug 29, 8:00 a.m. – 9:00 a.m.
Speakers: Luc Dekens & Kyle Ruddy
Luc and Kyle will take a look at the more advanced use-cases when using PowerCLI to automate actions in your environment. From proper object handling to diagnosing speed issues to debugging and more, this session is going to be a deep dive into the “what’s possible” with PowerCLI.

Session: NET1528BU – PowerNSX: Bringing the Power of PowerCLI to VMware NSX Data Center
Date: Wednesday, Aug 29, 8:30 a.m. – 9:30 a.m.
Speakers: Nicholas Bradford & Anthony Burke
Nick and Anthony will show attendees what PowerNSX is and how to use it to help automate anything from ad hoc queries to complete NSX data center logical topologies.

Session: HCI2061BU – Forget Click, Click, Click: Manage vSAN at Scale with PowerCLI
Date: Wednesday, Aug 29, 11:00 a.m. – 12:00 p.m.
Speakers: Jase McCarty & Kyle Ruddy
Jase and Kyle will take an in-depth look at the ways vSAN can be managed with PowerCLI to easily achieve consistency and repeatability at scale.

Session: DEV2828BU – Automating IT Ops with Dispatch Serverless Framework
Date: Wednesday, Aug 29, 11:30 a.m. – 12:30 p.m.
Speakers: Alan Renouf & Berndt Jung
Alan and Berndt show off the power of serverless with Dispatch. Attendees will see how to setup and configure Dispatch, plus how to control event triggers with familiar tools, like PowerCLI, and existing scripts.

Session: NET1642BU – NSX-PowerOps: Day2 Ops, NSX Health, Security, and Automated Documentation
Date: Wednesday, Aug 29, 11:30 a.m. – 12:30 p.m.
Speakers: Hammad Alam & Puneet Chawla
Hammad and Puneet will discuss a community-built tool, NSX-PowerOps, which uses tools like PowerCLI and PowerNSX to create documentation of your environment.

Session: VIN3327BU – Documenting Your Virtual Infrastructure with PowerShell and PowerCLI
Date: Wednesday, Aug 29, 2:00 p.m. – 3:00 p.m.
Speakers: Tim Carman & Matthew Allford
Tim and Matthew take the burden of documentation and applies it to an open-sourced project which helps to document environments using nothing but PowerCLI.

VMware {code} Power Sessions

Session: CODE5560U – Closer look at vSphere programming and CLI interfaces
Date: Tuesday, Aug 28, 12:30 p.m. – 1:00 p.m.
Speaker: Vikas Shitole
Vikas will show off the wide variety of APIs, CLIs, and SDKs available for use with vSphere and how to get started with each one.

Session: CODE5547U – Deep dive into the Horizon View APIs & PowerShell module
Date: Tuesday, Aug 28, 1:00 p.m. – 1:30 p.m.
Speaker: Wouter Kursten
Wouter shows off some of the fantastic new cmdlets that have been created and added to the Horizon View Helper module which can be used to enable PowerCLI based automation of Horizon View.

Session: CODE5549U – A better way to see PowerCLI data
Date: Tuesday, Aug 28, 1:30 p.m. – 2:00 p.m.
Speaker: Jake Blecha
Jake will show how to wrangle all the object data PowerCLI can return to get access to what you’re looking for in the format you want.

Session: CODE5540U – PowerCLI Lint
Date: Tuesday, Aug 28, 2:15 p.m. – 2:30 p.m.
Speaker: Justin Sider
Justin will apply the concept of Linting and unity testing to PowerCLI code and introduce some tools to help make the process easier so you can write better and re-usable code.

Session: CODE5622U – It’s Magic! Automating VMware Cloud on AWS
Date: TBD
Speaker: Ryan Kelly
Ryan discusses how to start interacting with the VMware Cloud on AWS APIs with PowerCLI to automate your scalable, highly resilient, infrastructure in the cloud.

vBrownBag Sessions

Session: VMTN5513U – vDeploy – PowerCLI only method to fully deploy a VM
Date: Monday, Aug 27, 1:00 p.m. – 1:15 p.m.
Speaker: Russell Hamker
Russell will walk you through vDeploy, covering what it is, how to use it, and what it supports so you can automate the deployment of a Windows VM to any environment.

Session: VMTN5522U – Automating Troubleshooting with vSphere Operations Manager
Date: Monday, Aug 27, 1:45 p.m. – 2:00 p.m.
Speaker: Thom Greene
Thom will show how to leverage the vRealize Operations PowerCLI module to automate your troubleshooting workflows.

Session: VMTN5535U – Strategies to starting with PowerCLI
Date: Monday, Aug 27, 5:00 p.m. – 5:15 p.m.
Speaker: Seth Crosby
Seth will take you through a handful of valuable strategies for helping you overcome what is holding you back from managing your VMware infrastructure like a pro, with PowerCLI.

Session: VMTN5605U – Getting Started with GitHub for PowerCLI Users
Date: Tuesday, Aug 28, 5:15 p.m. – 5:30 p.m.
Speaker: Justin Sider
Justin will walk through a few different typical scenarios that system administrator experience and how GitHub can solve those issues. From public to private to internal repositories, attendees will gain an understanding how what each are, how to use the, and even some tips on securing them.

Session: VMTN5597U – Powershell, it’s not just for Windows anymore
Date: Wednesday, Aug 29, 10:45 a.m. – 11:00 a.m.
Speaker: Chris Nakagaki
Chris will demonstrate how to easily get up and running with PowerShell Core and PowerCLI on a Mac or Linux system, and where it could possibly go from here.

Session: VMTN5614U – Gentle Shutdown of a 2-node Starwind HCI Cluster using PowerCLI
Date: Thursday, Aug 30, 1:30 p.m. – 1:45 p.m.
Speaker: Matt Langguth
Matt will walk you through an issue with StarWind HCI clusters and how PowerCLI can come to the rescue and overcome the issue.

Meet the Experts

Session: Automate Your VMware Cloud on AWS Environment with Paul Gifford
Date: MTE5097U – Sunday, Aug 26, 3:15 p.m. – 4:00 p.m.
Come meet with Paul to discuss the automation of VMware Cloud on AWS with tools like PowerCLI.

Session: vSphere Automation and VMware Cloud on AWS with William Lam
Date: MTE5013U – Tuesday, Aug 28, 1:15 p.m. – 2:00 p.m.
Come meet with William to discuss vSphere and VMware Cloud on AWS based automation.

Session: PowerCLI with Kyle Ruddy
Date 1: MTE5063U – Wednesday, Aug 29, 3:15 p.m. – 4:00 p.m.
Date 2: MTE5007U – Thursday, Aug 30, 10:45 a.m. – 11:30 a.m.
Come meet with Kyle to discuss any thoughts, ideas, issues, or anything that comes to mind regarding PowerCLI.

Hands on Labs

Lab: SPL-1911-05-SDC_U – VMware vSphere Automation – PowerCLI
Date: Anytime the HOL area is open and available
Get hands-on with VMware PowerCLI. Gain familiarity with the tool, and then dive deeper into the functionality available with real world examples. Both new and experienced users are sure to learn something new about automating their environments.

Session: ELW-1911-05-SDC_U – Expert-Led Workshop – VMware vSphere Automation – PowerCLI
Date 1: Monday, Aug 27, 2:30 p.m. – 4:00 p.m.
Date 2: Tuesday, Aug 28, 12:30 p.m. – 2:00 p.m.
Speaker: Howard Shoobe
Howard will show attendees how to get hands-on with VMware PowerCLI. You will gain familiarity with the tool, and then dive deeper into the functionality available with real world examples.

Hackathon

And last, but certainly not least, the VMware {code} Hackathon! If you’ve never been or haven’t heard of it, this is a fantastic event to get involved with other community members to do some coding! There’s no requirement to know how to code whatsoever. In fact, there are some trainings running before the Hackathon to help you get orientated.

Session: CODEHACK – VMware {code} Hackathon
Date: Monday, Aug 27, 6:30 p.m. – 11:30 p.m.
Join VMware {code} for the third annual hackathon!

Session: HACK6013U – PowerShell Primer: Prepping for Hackathon Success!
Date: Monday, Aug 27, 6:30 p.m. – 7:30 p.m.
Speaker: Kyle Ruddy
Kyle will cover a number of scenarios to help attendees get up to speed so they can use PowerShell to succeed in their Hackathon quest.

Summary

If you’re looking for PowerCLI content, VMworld is the place to be this year! With 10 sessions, over 10 community sessions, multiple meet the experts, and several hands-on activities, there’s something for everyone regardless of skill level. Make sure you’re registered for VMworld and get these sessions added to your schedule today!

Automating File-Based Backups of vCenter Server Appliance

Did you know the vCenter Server Appliance (VCSA) has file-based backup options?

This ability was actually released in vSphere 6.5. However, there was one feature in particular that was missing: a scheduler. I’m happy to say that as part of vSphere 6.7, the VCSA received a backup scheduler!

Recently, my teammate, Emad Younis released a couple cool walkthroughs to the vSphere Central site to manage file-based backup and restore actions. Under the covers, both of these actions are served up by vSphere’s RESTful APIs and therefore PowerCLI can also be used to automate these actions! One other benefit of using the API, you don’t have to hand out the root credentials. Users with the ‘SystemConfiguration.Administrators’ permission are able to perform all of the following tasks through the API and PowerCLI!

To perform a file-based backup with PowerCLI, we’ll need to make use of the CIS module. Since the CIS module is a low-level module, let’s see a couple examples of this in action.

Create a File-Based Backup

Let’s first start with the process to perform a backup.

First step, log in to the CIS Service for the VCSA:

Next, we need to find the appropriate service to perform a backup:

File-Based Backup Example: Listing CIS Services

Based on the output, we will want the ‘com.vmware.appliance.recovery.backup.job’ service. We will store that into a variable so we can easily interact with that specific service. To see the method we are going to use, take that variable and pipe it to ‘Get-Member’.

File-Based Backup Example - Working with the CIS Service

As part of the respose, we’ll see two important items. First, the ‘create’ method which we’ll use to actually create the backup job. Second, the ‘Help’ property. We can use ‘Help’ to help us form the input for the backup job with the following command:

We can now fill in each of the parameters with information for our environment. There are a couple caveats here. First, the ‘parts’ parameter is expecting an input of an array type. Second, each of the password parameters require a special type in order to be accepted.

Finally, having input all of our information, we can create the backup job!

File-Based Backup Example: Creating Backup Job

We can combine this into a nice script as follows:

Create a Scheduled File-Based Backup

Let’s now take a look at creating a scheduled backup job with PowerCLI.

Following a similar process to the last task, we will want to use one of the services we found previously called: com.vmware.appliance.recovery.backup.schedules

This time, we see two inputs are required. First, the schedule ID. Second, the specification which is similar to the prior example. The ‘Help’ property will be quite useful to create both specifications.

Much like the prior example, this one too has some caveats. The Schedule ID input can be a string of your choosing. For reference, performing this process in the UI creates a default ID of ‘default’. The scheduling recurrence configuration can be done in many ways through the ‘days’ property. If a daily backup is desired, there’s no need for any input and it can be left ‘unset’. If a specific day/s are desired, the input has to be of an array type.

Here’s a script which can be used to create a scheduled file-based backup:

Afterwards, if you log into the VCSA Appliance Management Interface (VAMI), your backup schedule should look much like the following:
File-Based Backup Example: Creating a Backup Schedule

Summary

The ability to create file-based backups of your vCenter Server is a function that is only available to the VCSA. This function is made possible by a set of RESTful APIs which PowerCLI can also consume, with the additional benefit of not being reliant on the root account! This blog post walked through examples of creating a file-based backup job and creating a scheduled file-based backup job.

More information about VCSA file-based backup can be found on the vSphere Central site: vCenter Server Appliance 6.7 File-Based Backup

Let us know in the comments how you’re automating your VCSA backups!

New Release: VMware PowerCLI 10.1.0

April has been a release heavy month for VMware. We have seen releases for vSphere 6.7, the entire vRealize suite, Site Recovery Manager 8.1, Horizon 7.4.1, and quite a few more. As of today, PowerCLI is being added to that list with the release of 10.1.0!

PowerCLI 10.1.0 offers the following updates:

  • Support for vSphere 6.7
  • Support for NSX-T 2.1
  • New VMware.Vim module
  • New cmdlets for managing Auto Deploy script bundles

Let’s take a look at those and some of the other updates.

Updated Support

Compatibility is something very important to PowerCLI. PowerCLI version 10.1.0 adds support for both vSphere 6.7 and NSX-T 2.1. This update gives you access to continue automating the latest and greatest VMware releases, plus have access to all those new APIs!

PowerCLI Compatability

New Module

This new version of PowerCLI brings our 20th module! This new module is named: VMware.Vim The goal of this module is to be able to allow you to have access to the latest vSphere APIs, including those available as part of VMware Cloud on AWS.

New Auto Deploy Cmdlets

Auto Deploy has two new cmdlets available to help with management of script bundles. These new cmdlets are:

  • Set-ScriptBundleAssociation
  • Remove-ScriptBundle

The Set-ScriptBundleAssociation cmdlet allows us to configure ESXi hosts to be associated with specific Auto Deploy script bundles.

The Remove-ScriptBundle cmdlet allows us to remove script bundles from Auto Deploy in an automated fashion. This functionality was actually requested by the community as PowerCLI Idea 114, so it’s really cool to see the direct impact the community can have.

General Updates

There’s a number of other improvements available in PowerCLI 10.1.0 as well. The first of which is to allow Import-VApp to support SHA-256 and SHA-512 hash algorithms. Next, we have deprecated the ‘Version’ parameter for the New-VM and Set-VM cmdlets. This parameter has been replaced by ‘HardwareVersion’. The same deprecation has been applied to the VirtualMachine object as a whole. Instead of referencing the ‘Version’ property, reference the ‘HardwareVersion’ property instead. Then, the Get-TagAssignment cmdlet has had the functionality corrected so we can query tags on datastore clusters. Another shout out to the community for this update, since that’s how this was brought to our attention! Also, we have made some updates to the process of migrating a VM to a VMware Cloud on AWS environment.

Lastly, PowerCLI 10.0.0 brought a bit of a change when it comes to handling vCenter and ESXi certificates. Instead of producing a warning when connecting to resources using invalid or self-signed certificates, PowerCLI now produces an error. We found some valid certificates were still producing an error and have corrected that process with PowerCLI 10.1.0.

If you do need to change PowerCLI’s configuration for handling certificate validation, the following code can be used to ignore those invalid or self-signed certificates:

Wrap-Up

PowerCLI 10.1.0 is the second release of the year and its only April! This release brought support for both vSphere 6.7 and NSX-T 2.1. A new module was introduced, VMware.Vim, making PowerCLI 20 modules strong. Two new cmdlets were added to help in the management of Auto Deploy script bundles! Plus, there were a number of other improvements added as well.

Remember, updating your PowerCLI modules is now as easy as ‘Update-Module VMware.PowerCLI’.

Example: Update-Module to PowerCLI 10.1.0

For more information on changes made in VMware PowerCLI 10.1.0, including improvements, security enhancements, and deprecated features, see the VMware PowerCLI Change Log. For more information on specific product features, see the VMware PowerCLI 10.1.0 User’s Guide. For more information on specific cmdlets, see the VMware PowerCLI 10.1.0 Cmdlet Reference.