Home > Blogs > VMware PowerCLI Blog

New Release: Learning PowerCLI – Second Edition Book

Learning PowerCLI - Second EditionRecently, the new book Learning PowerCLI – Second Edition was published by Packt Publishing. Learning PowerCLI – Second Edition contains 517 pages of PowerCLI goodness. The book starts with downloading and installing PowerCLI. It continues with basic PowerCLI concepts, and working with PowerShell objects. Managing vSphere host, virtual machines, virtual networks, storage, high availability, clusters, and vCenter Server are the following topics. After patching ESXi hosts and upgrading virtual machines using vSphere Update Manager, managing VMware vCloud Director and vCloud Air, using Site Recovery Manager, vRealize Operations Manager, and REST API to manage NSX and vRealize Automation, the book finishes with a chapter about reporting.

If you are new to PowerCLI or have some PowerCLI experience and want to improve your PowerCLI skills, Learning PowerCLI – Second Edition will teach you to use PowerCLI to automate your work!

What’s New

Compared to the first edition, the following new topics are added in Learning PowerCLI – Second Edition:

  • Importing OVF or OVA packages
  • Using Tags
  • Using VMware vSAN
  • Using vSphere storage policy-based management
  • Configuring enhanced vMotion compatibility (EVC) mode
  • Patching ESXi hosts and upgrading virtual machines
  • Managing VMware vCloud Director and vCloud Air
  • Using Site Recovery Manager
  • Using vRealize Operations Manager
  • Using REST API to manage NSX and vRealize Automation

Learning PowerCLI – Second Edition is available exclusively from Packt Publishing: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

About the Author

Learning PowerCLI – Second Edition is written by Robert van den Nieuwendijk. Robert is a freelance system engineer living and working in the Netherlands. He is a VMware vExpert since 2012 and a moderator of the VMware VMTN Communities. Robert has a blog at http://rvdnieuwendijk.com. You can follow Robert on Twitter as @rvdnieuwendijk.

Getting Started with PowerCLI for Horizon View

PowerCLI 6.5 introduced a brand new, completely re-written, module for Horizon View that is leaps and bounds better than the prior release. As an automation fanatic and former View administrator, PowerCLI’s offering for Horizon View has always been an important part of my toolbox.

Graeme Gordon, a Senior EUC Architect on our EUC Technical Marketing team, has created a terrific video on how to get started using this new module that we recommend checking out.

Watch the Video

Also, here’s a direct link to the blog post Graeme references in the video: Getting Started with PowerCLI 6.5 for Horizon View

New Release: PowerCLI 6.5 R1 Poster!

PowerCLI 6.5 was a big release for us. We changed the name to reflect that we’re doing a bit more than just vSphere these days, we fully converted our snap-ins to modules, and so many more upgrades and updates. There are always a lot of asks for it with every release, so I am extremely happy to finally announce the release of the VMware PowerCLI 6.5 R1 poster!

The poster features a bit of a new layout, but still features all of our cmdlets and some associated examples. It also calls out the PowerCLI Community Repository, along with some of what it contains thanks to our amazing community members, and some of the PowerCLI focused flings!

PowerCLI Poster

VMware PowerCLI 6.5 R1 Poster

If you’re looking to print one out, they are best at 39 inches width by 19 inches height.

Also, be on the lookout for these posters coming to a VMworld and/or VMUG near you!

Help Shape PowerCLI’s Future – Poll

Community feedback has always played an important role in how PowerCLI has evolved and improved. Whether it’s the desire to convert from snapins to modules, adding additional functionalities to existing cmdlets, or creating brand new cmdlets and modules, the feedback we receive has always been extremely important.

This time we have an ask to help shape the future of PowerCLI’s packaging, installation, and upgrade process in the form of an online poll available here: https://www.surveymonkey.com/r/HGQDJFQ

Giving a little context around the poll, there have been a lot of asks around getting PowerCLI into the PowerShell Gallery. The PowerShell Gallery is an online repository containing an amazing amount of PowerShell modules and scripts. The PowerShell Gallery allows users the ability to search, install, update, and uninstall these resources directly from a PowerShell session.

Taking a look at how we distribute PowerCLI today, this move would have some major impacts. Instead of logging into my.vmware.com then downloading and installing PowerCLI through an MSI, users could simply open PowerShell and run:

Install-Module -Name PowerCLI

Updating would change as well, as users could then run:

Update-Module -Name PowerCLI

With the changes in these installation methods, it would also mean the start menu and desktop shortcuts would no longer be automatically created at time of install.

Last big impact would be to offline installations. Since the PowerShell Gallery is an online repository, users would have to access the gallery using a system that has internet access, running a command that looks something like the following, and then completing the install by copying the module over to the offline system where it can now be imported:

Save-Module -LiteralPath "C:\MyLocalModules\" -Name PowerCLI

The last question is optional and is asking for an email address since we’ll have some goodies available as giveaways!

If you’d like some additional information about the PowerShell Gallery, see the following link: https://msdn.microsoft.com/en-us/powershell/gallery/psgallery/psgallery_gettingstarted

Here’s a link to the survey: https://www.surveymonkey.com/r/HGQDJFQ

Again, thanks to everyone for helping make PowerCLI awesome!

Welcoming a New Member to the Team

Jeffrey Snover and Jake Robinson

Jake Robinson (right) with PowerShell “father”, Jeffrey Snover (left)

I’d like to welcome someone new to the PowerCLI team: Jake Robinson.

Jake is our new Senior Product Manager for Automation Frameworks and CLIs. This means he’s going to be spending a lot of time focusing on the future of PowerCLI!

Jake has been long been a PowerCLI user. He’s even presented PowerCLI sessions at VMware and PowerShell User Groups as well as vBrownBag.

In his spare time, Jake enjoys brewing beer, playing video games, and grooming his epic beard.

When asked about the future of PowerCLI, Jake said: We are in the Post-GUI era, and PowerCLI has been, and will continue to be, the best user interface for VMware products, not just vSphere!

I think it’s fair to say the future of PowerCLI is bright!

You can find Jake’s personal blog at http://geekafterfive.com/ and contact him on Twitter via @jakerobinson

Spotlight on the Move-VM Cmdlet including PowerCLI 6.5 Enhancements

VMware PowerCLI 6.5’s release introduced a lot of new cmdlets and improvements to existing cmdlets. One of my favorite improved cmdlets has to be Move-VM. Move-VM was already a very versatile cmdlet before this new release. It could be used to move a VM between hosts, datastores, resource pools, clusters, to new folders, to a vApp, and so forth. Now, with PowerCLI 6.5 R1, Move-VM can move VMs between vCenters! We can even take that a step further, Move-VM can move VMs to vCenters which are not linked together by SSO domain. That’s something that cannot be done by the web client!

Let’s start by taking a look at the newest addition to the cmdlet, migrating VMs between vCenters.

Cross vCenter vMotion

Cross vCenter vMotion was introduced with vSphere 6.0. It’s proved to be a great feature that opens up new options in flexibly managing a vSphere environment. One of the limitations in using cross vCenter vMotion by way of the Web Client is that it can’t migrate VMs between SSO domains. This is where the usage of PowerCLI is hugely beneficial because PowerCLI allows users to fill that gap. The key to PowerCLI being able to overcome that limitation is due to its ability to connect to multiple vCenter servers at the same time.

In order to perform a cross vCenter vMotion, there are a couple parameters that are needed:

  • Active Connection to both Source and Destination vCenters
  • Source vCenter
    • VM
    • VM’s Network Adapter/s
  • Destination vCenter
    • Destination ESXi Host
    • Destination Datastore
    • Destination PortGroup/s

Here’s some example code on how that can be accomplished:

$sourceVCConn = Connect-VIServer -Server $sourceVC -user $sourceVCUsername -password $sourceVCPassword
$destVCConn = Connect-VIServer -Server $destVC -user $destVCUsername -password $destVCpassword

$vm = Get-VM $vmname -Server $sourceVCConn
$networkAdapter = Get-NetworkAdapter -VM $vm -Server $sourceVCConn

$destination = Get-VMHost -Server $destVCConn
$destinationPortGroup = Get-VDPortgroup -VDSwitch $switchname -Name VM-Network1 -Server $destVCConn
$destinationDatastore = Get-Datastore $datastorename -Server $destVCConn

Move-VM -VM $vm -Destination $destination -NetworkAdapter $networkAdapter -PortGroup $destinationPortGroup -Datastore $destinationDatastore

I also want to filling in a couple informative gaps in the above code:

  • Due to the cross vCenter vMotion functionality being added in as part of vSphere 6.0, it can only be performed against vCenter servers of 6.0 and newer.
  • The destination parameter only accepts an individual ESXi host. A workaround could look like the following code:
    $destination = Get-Cluster –Name Cluster01 –Server $destVCConn | Get-VMHost | Select-Object –First 1
  • The datastore parameter only accepts an individual datastore. A workaround could look like the following code:
    $destinationDatastore = Get-DatastoreCluster –Name DSCluster01 –Server $destVCConn | Get-Datastore | Sort-Object -Property FreeSpaceGB -Descending | Select-Object -First 1

Multiple NIC VM vMotion

If you look at the example code above, specifically at the network pieces, you’ll notice that it only focuses on moving a VM with a single NIC. However, both the NetworkAdapter and PortGroup parameters accept arrays. This means that you can pass multiple objects to those parameters.

One key thing to note is that the first item in each array will be referenced together, then the second items will be referenced together, and so on and so forth. If there are multiple network adapters and only one portgroup specified, the network adapters will all be assigned to the same portgroup. If there is only a single network adapter and multiple portgroups specified, the command will error out.

Here’s an example of doing a Cross vCenter vMotion on a VM that has multiple NICs:
Move-VM with Multiple Network Adapters

Conclusion

The above examples are just the tip of showing just how versatile the Move-VM cmdlet really is. Let us know how you’re using Move-VM in your environment in the comments below!

For more information on its use in your environment, see the PowerCLI cmdlet reference on Move-VM.

Saying Farewell to Snapins!

One of the key improvements to the VMware PowerCLI 6.5 R1 release is the absence of PowerShell snapins. All of the remaining snapins have been converted to modules!

Snapin History

If you don’t know why this is such a big deal, let me take a second to cover some history on snapins. Going back to the days of PowerShell version 1, snapins were the only way to extend the shell, or add additional features and functionalities. The issue with snapins begin due to how they can only be written in a .NET programming language and then have to be assembled before being handed off to the user. Then, once the user has them, the issues continue due to the snapins having to be installed and registered to each individual system a user wishes to use them on. Snapins also lack the ability to explicitly define dependencies, this causes issues for a product like PowerCLI which is comprised of several individual components.

PowerShell version 2 introduced modules, which resolved a majority of those issues. Modules can still be written in any .NET programming language, or can even be written in PowerShell itself! Modules are mobile and don’t require any registrations. Once the modules are in hand, they can be referenced automatically by placing them in one of the proper folders or by specifying the directory path to where they reside for each system requiring access.

Finding Snapins

This change in architecture introduces an issue for already created scripts which are trying to load the old VMware snapins. Instead of performing something that looks like:

Add-PSSnapin –Name VM*

We’re recommending a replacement from that command to this command:

Get-Module –ListAvailable VM* | Import-Module

We’re not going to leave the rest to you to handle. There’s some functions which have been added to the PowerCLI Community Repository which will point out which scripts contain that line. There’s also a function which can comment out that line and add the new recommended command. These functions are available within the Update_PowerCLI_Scripts.ps1 script.

The first function is “Get-PowerCLISnapinUse” and will show what scripts (.ps1 extensioned) include the string “Add-PSSnapin*VM*” and will display the file name, line where the string resides, path to the directory, and the full path of the file.

Get-PowerCLISnapinUse Example Output

The second function is “Update-PowerCLISnapinUse” and is based around adding the new Import-Module command and commenting that string out.

Results from using Update-PowerCLISnapinUse

Additionally, if you’ve already updated your version of PowerCLI, you may have noticed the installation directory has changed as well. If you have the “Initialize-PowerCLIEnvironment” script hardcoded into your scripts, there are also some functions to handle that as well. The functions for that are done by way of “Get-PowerCLIInitialization” and “Update-PowerCLIInitialization”. These functions work similarly to the above, however the “Update-PowerCLIInitialization” function just updates the directory path and does not comment anything out.

Conclusion

VMware PowerCLI moving over to be completely modules is a huge accomplishment in this newest release. As always, it’s backwards compatible and we recommend upgrading to the latest version.

You can find the PowerCLI 6.5 Release 1 download HERE.

New Release: PowerCLI 6.5 R1

There’s been a lot of buzz around PowerCLI lately, and we’re keeping it going! It gives me great pleasure to announce the general availability of VMware PowerCLI 6.5 Release 1!

Before diving in on all the new features, it’s worth noting that these features are all created based on feedback taken directly from the users. Please help us make the product better by letting us know what would make PowerCLI easier to use and what would make your automation tasks less painful! The PowerCLI Product Manager, Development Team and I, would like to extend a huge Thank You to the community for their great feedback and consistent drive to enhance the product.

Cmdlet Updates

The Core vSphere module has received a number of updates as well as stability and performance improvements. The most notable updates include cmdlets based around VM creation and management. The ‘Move-VM’ cmdlet now supports the ability to vMotion VMs between vCenters which is known as Cross vCenter vMotion. Performing a Cross vCenter vMotion with PowerCLI also allows the VM to traverse between separate SSO domains too! This is something not available with the GUI. The ‘New-VM cmdlet now supports configuring a VM to have a specific number of CPU cores. Then, the ‘Open-VMConsoleWindow’ has been updated to provide access to the latest and greatest version of the VMware Remote Console (VMRC). Lastly, various cmdlets have received updated views to allow access to the new vSphere 6.5 APIs!

Storage Module Updates

The PowerCLI Storage module has been a big focus on this release. A lot of functionality has been added around vSAN, VVOLs, and the handling of virtual disks. The vSAN cmdlets have been bolstered to more than a dozen cmdlets which are focused on the entire lifecycle of a vSAN cluster. The entire vSAN cluster creation process can be automated with PowerCLI as well as running tests, updating the HCL database, and much more!

  • Get-VsanClusterConfiguration
  • Get-VsanDisk
  • Get-VsanDiskGroup
  • Get-VsanFaultDomain
  • Get-VsanResyncingComponent
  • Get-VsanSpaceUsage
  • New-VsanDisk
  • New-VsanDiskGroup
  • New-VsanFaultDomain
  • Remove-VsanDisk
  • Remove-VsanDiskGroup
  • Remove-VsanFaultDomain
  • Set-VsanClusterConfiguration
  • Set-VsanFaultDomain
  • Test-VsanClusterHealth
  • Test-VsanNetworkPerformance
  • Test-VsanStoragePerformance
  • Test-VsanVMCreation
  • Update-VsanHclDatabase

vSphere 6.5 introduces a new way to handle the management of virtual disks. Instead of managing a VM’s hard disks through the VM, they can now be managed independently with new PowerCLI cmdlets. This allows the handling of a virtual disk’s lifecycle to be decoupled from the lifecycle of a VM. This adds a ton of flexibility!

  • Copy-VDisk
  • Get-VDisk
  • Move-VDisk
  • New-VDisk
  • Remove-VDisk
  • Set-VDisk

PowerCLI has been updated to include new cmdlets that allow for the automated management of the VVOL replication features which are new to vSphere 6.5. Some of the new features include finding fault domains and replication groups, syncing replication groups, as well as preparing for and starting the failover process to the target site.

  • Get-SpbmFaultDomain
  • Get-SpbmReplicationGroup
  • Get-SpbmReplicationPair
  • Start-SpbmReplicationFailover
  • Start-SpbmReplicationPrepareFailover
  • Sync-SpbmReplicationGroup

Horizon Module

A brand-new module has been included to work with VMware Horizon! This has been a long time coming and has finally been released. The module can be installed anywhere and then remotely connect to the Horizon Connection server, a huge improvement over the last offering. Speaking of improvements, the module provides access to 100% of the public API through the Connect-HVServer and Disconnect-HVServer cmdlets. Keep an eye on the PowerCLI-Examples Github repo for functions allowing you to easily work with this module and provide sample code!

Compatibility

As with all versions of PowerCLI, it’s also backwards compatible going back to vSphere 5.5!

PowerCLI and vSphere Compatibility

The Storage module is compatible with vSAN 6.0 and newer, as well as Site Recovery Manager 6.1 and newer!

PowerCLI and vSAN SRM Compatibility

Last, the Horizon module is compatible with Horizon 7.0.2.

PowerCLI and Horizon Compatibility

PowerCLI Core

As if this release wasn’t enough, PowerCLI Core also has support for the new 6.5 vSphere APIs! This ensures those core vSphere cmdlets and Views are available to other operating systems PowerCLI Core operates on as well!

More Information and Download

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

You can find the PowerCLI 6.5 Release 1 download HERE. Get it today!

What to Expect in PowerCLI 6.5?

PowerCLI 6.5 was announced last week at VMworld Europe and, while we are waiting for it to be generally available, we thought it would be a good time to give you an idea of what to look forward to in the meantime.

What’s New

VMware, with PowerCLI, was one of the early adopters of PowerShell and in the PowerShell v1.0 days, snap-ins were the only way to extend the shell for additional functionality. With each release of PowerCLI we’ve been progressing the switch over to using modules and with PowerCLI 6.5, it will be 100% module based! Thanks to all the hard work of the PowerCLI Engineering team, the migration is finally complete!

No More Snapins!

Core vSphere Module

The Core vSphere module has received a number of new updates too. The Move-VM cmdlet now supports cross vCenter vMotion. The ability to specify the number of cores for a VM has been added to the New-VM and Set-VM cmdlets. The last of the big updates to the Core module is that the Open-VMConsoleWindow now uses the latest version of the VMware Remote Client (VMRC).

Cross vCenter vMotion

VSAN Cmdlets

The storage module has been a big focus and has some major new updates as well. There are a lot of new VSAN cmdlets being introduced in this release. The ability to get and set VSAN cluster configurations, manage VSAN fault domains, update the HCL database, perform various VSAN tests, and a few other features too!

VSAN Cluster Configuration

VVol Cmdlets

VVols
Continuing on the topic of the storage module, there are also some fantastic new cmdlets added to also work with VVOL replication. We can now retrieve and sync replication groups as well as retrieving and/or starting the replication failover preparation, and even starting the replication failover itself.

Horizon Module

Last, but certainly not least, of the big updates to PowerCLI 6.5 is a complete re-write of the Horizon View module. The module can be ran from anywhere, instead of just on the View Connection server. The module is also installed with the PowerCLI installer. The module will give you access to the Horizon View Public API and there will be some advanced functions available on the PowerCLI Example Scripts GitHub repo upon release.

New Horizon Module

Summary

There’s lots of cool new features and improvements coming in the next release of VMware PowerCLI, and it will be released side by side with vSphere 6.5 later this year. Over the next couple of months there will be several blog posts posted which will highlight many of these new features and how to put them to use in your own environments.

PowerCLI Core Fling – Available For Download!

I am extremely excited to announce that the PowerCLI Core Fling has been released and is available for download!

Before getting to the download link, let’s cover a couple things first.

This release is based on, and requires, Microsoft PowerShell Core and .NET core. If you do not already have it installed, see the accompanied documentation for a walkthrough on getting started.

Feedback is very much welcomed. Please use the Fling site’s comment section to submit feedback. Keep in mind, we improve the product based off of your feedback, so please do let us know!

Enough suspense, the PowerCLI Core Fling is available here: https://labs.vmware.com/flings/powercli-core

Check out this demo of the install process on a Linux system:

Enjoy, and don’t forget the feedback!