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

Tag Archives: PowerShell

PowerCLI 6.5.1 Installation Walkthrough

We released PowerCLI 6.5.1 two weeks ago and the response has been incredible! The VMware.PowerCLI module is closing in on 4,000 downloads from the PowerShell Gallery and we’ve received a ton of good feedback.

There seems to be quite a few questions and comments over this new installation method so I created a walkthrough video to illustrate the process for PowerShell version 5.0 as well as for versions 3.0 and 4.0. We’ve also collected the most common errors and issues during the installation process and included troubleshooting steps for those below.

Walkthrough Video

Common Troubleshooting Steps

If there happens to be an issue during the installation process, here’s a couple of the top tips we have seen on working around them:

  • The process cannot access the file ‘C:\Users\…\AppData\Local\Temp\…’
    • Ensure previous versions of PowerCLI are uninstalled and all PowerShell sessions are closed.
    • Verify the file isn’t being blocked by an antivirus software.
  • A command with name ‘verb-noun’ is already available on this system.
    • This is due to a module already available on the system containing that cmdlet. The more common example modules include FailoverClusters and HyperV.
    • Append “-AllowClobber” to the Install-Module command line.
      Example: Install-Module –Name VMware.PowerCLI –Scope CurrentUser –AllowClobber
  • No match was found for the specified search criteria and module name ‘VMware.PowerCLI’
    • This could be due to a lack of connectivity to the PowerShell Gallery.
    • If a proxy can be used, the “Install-Module” cmdlet can configure proxy connectivity with the “Proxy” and “ProxyCredential” parameters.
      Example: Install-Module –Name VMware.PowerCLI –Scope CurrentUser –Proxy ‘http://my.proxy.company.com’
  • Could not get response from query ‘https://www.powershellgallery.com/api/v2/package/VMware.VimAutomation.Core/…’
    • This warning is just indicating there is an issue establishing connectivity to the PowerShell Gallery. Retry the installation at a later point in time and it should succeed.

Summary

We are really excited about this release and what this means for the future of PowerCLI! Upgrade to PowerCLI 6.5.1 today, and keep that feedback rolling in!

Thoughts around PowerCLI and the Powershell Gallery

I am *very* excited to share some thoughts and possibilities for PowerCLI.

Packaging and Installation are big areas we have been looking at. We have heard loud and clear that our customers wanted to embrace modules and in our recent releases we have moved away from snapins into modules. We’re now looking at how we package the modules and deliver them to our users.

One possibility would be releasing PowerCLI exclusively from the Powershell Gallery, the central repository for Powershell modules. The benefits of this would be great, as it provides easy installation and upgrade, follows Powershell patterns for modules, and most importantly would allow us to deliver PowerCLI to multiple platforms, such as Linux and MacOS.

Here is an idea of what we are currently thinking:

  1. You would need to make sure you have the latest Powershell. WMF 5.1 is required for the PowershellGet cmdlets, which includes install-module. (You may want to do this now!)
  2. Make sure $env:PSModulePath includes C:\Program Files\WindowsPowerShell\Modules . This is only precautionary because it should already be set, but you should check anyway.
  3. Prior to installation of the PowerCLI from the Microsoft Gallery you would need to uninstall any previous version of PowerCLI that was installed by MSI.
  4. You would no longer have PowerCLI shortcuts on your desktop. PowerCLI would be immediately available when you run powershell, no Import-Module required. If you really miss the icon, find me at a conference and I’ll give you a sticker! 🙂
  5. Installation of PowerCLI on machines that cannot access the Powershell Gallery can be done by saving the module to a thumb drive or network share accessible to the installation target and dropping the files in the module folder of the destination computer or using Install-Module with a path to the downloaded file.
  6. We are thinking about using Update-Module in the future to make geting the latest bits faster and easier!

I understand that change can be hard, so I’m giving you the opportunity to tell us why (or why not) a Powershell Gallery installation/update would not work for you.

Regarding the results from the survey we recently held, an extremely high percentage of the respondents prefer the Gallery installation for ease of installation and updates. Still, there were a few respondents that had some concerns that I want to address here.

  1. “The Powershell Gallery is not as secure as downloading an MSI from vmware.com” – This is not true. We digitally sign all PowerCLI files as we always have, guaranteeing authenticity. PowershellGet has built-in verification of the digital signature, and will not install unsigned modules unless you explicitly skip the publisher check.
  2. “This makes offline installation/upgrades much harder” – So far, I’ve identified two different methods of offline installation and both require less steps (and ZERO mouse clicks). Method one uses Save-Module to copy to a network drive accessible by the ‘offline’ machine. You could also save to a USB drive or any other storage location that your installation target can access. Method two uses Invoke-WebRequest to download the package and can again be saved to a location of your choosing. Either of these options are still far easier than the current process.

Conclusion

In my prior life as a customer, I could only dream of installation and upgrades being this easy. By releasing to the gallery, it would not only make *that* dream come true, but would also give us the ability to accelerate our releases to get improvements out for you to enjoy much sooner.

Added to this we would be bringing PowerCLI back in line with the PowerShell patterns and ensuring future powershell enhancements made around modules and module tooling could easily be consumed with PowerCLI.

I hope you join with me in the excitement of the amazing opportunities we have with PowerCLI!

What are you excited or concerned about with a Powershell Gallery release? Let us know in the comments here!

 

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!

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.

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!

VMworld Sneak Peek: INF8038 – Getting Started with PowerShell and PowerCLI

VMworld US 2016

VMworld Session INF8038 is going to be great regardless of whether you’re new to PowerShell or just in need of a refresher. The session will be packed full of information from getting your PowerShell profile setup to understanding the difference between a module and a snap-in, then starting down the path of using logic statements and even creating your own scripts.

Check out this video by Chris Wahl to get a sneak peek on what to expect:

Don’t forget to register for the session by way of the VMworld Content Catalog!

Updating the VMware PowerCLI Community Repository!

PowerCLI + GitHub
If you’ve ever tried searching for a script or a module before, you know it’s not the easiest thing to accomplish. This sentiment has been coming up more and more as of late. There’s a ton of amazing PowerCLI scripts and modules, PowerActions scripts, DSC resources, and so forth contributed by the community and openly available.

The VMware PowerCLI Community Repository is a central location where anyone can contribute their own resources. The repository features a Principles of Operations document to help guide contributors along the process of using, creating, and updating resources which are contained within the repository.

This community repository will also feature several community members as board members. As part of the board, they will be asked to help maintain the repository with tasks such as testing and providing feedback on all submitted resources, communicating with other board members in order to approve pull requests, and continuing to be good community advocates of PowerCLI and the community repository.

I’d like to thank and welcome the following board members:
Josh Atwell (Community Member)
Luc Dekens (Community Member)
Jonathan Medd (Community Member)
Alan Renouf (VMware)
Kyle Ruddy (VMware)
Rynardt Spies (Community Member)

Now that we have the announcements out of the way, let’s take a look at how to dig in and get started.

Getting Started

Accessing the Repository

Downloading the Repository for Local Access
If you happen to be new to GitHub and want to access the contents of the repository, one of the easiest ways to that is to just download a copy of it directly from GitHub to your local system:

  1. Load the following GitHub repository page: VMware PowerCLI Community Repository
  2. Click on the green “Clone or Download” button and then click “Download ZIP”
  3. Once downloaded, extract the zip file to the location of your choosing
  4. At this point, you now have a local copy of the repository

Download PowerCLI Repository

Creating Your Own GitHub Based Access Point
Another one of the easiest ways to access the repository contents is to “fork” it, which places a copy of the repository within your account:

  1. Login (or signup) to GitHub
  2. Load the following GitHub repository page: VMware PowerCLI Community Repository
  3. Click on the Fork button, which will create a copy of the repository and place it in the GitHub based location of your choosing.

Adding Resources

GitHub – Copy/Paste Option
If you happen to want to contribute a script or other resource and are new to GitHub, you have the ability to copy and paste your resource directly to the repository:

  1. Within the community repository, browse to the appropriate section (example: Scripts)
  2. Select the “Create new file” button
  3. On the new page, enter a file name, enter the resource’s information
  4. Within the “Commit new file” area, enter the title and description, then select “Create a new branch for this commit…” and enter a sensical branch name
  5. Click “Propose new file”
  6. On the “Open a pull request” page, click “Create pull request”

Submit to PowerCLI Repository

GitHub – Upload Files Option
Similarly to the copy and paste option above, you can also upload your resource directly to the repository as well:

  1. Within the community repository, browse to the appropriate section (example: Modules)
  2. Select the “Upload files” button
  3. On the new page, drag or choose the files to add
  4. Within the “Commit changes” area, enter the title and description, then select “Create a new branch for this commit…” and enter a sensical branch name
  5. Click “Propose new file”
  6. On the “Open a pull request” page, click “Create pull request”

GitHub Desktop Client

There are numerous other ways to interact with the community repository other than just the GitHub web interface. The GitHub Desktop is a great way to setup and streamline your interaction with any GitHub Repository. More information is available at GitHub’s Desktop Client Getting Started page.

GitHub Desktop Client

Conclusion

The goal of the VMware PowerCLI Community Repository is to bring the great PowerCLI resources from the community into a central location that’s easy to find, search, use, and contribute to regardless of the user’s technical skill level.

If there’s any questions, comments, or feedback, join us in the VMware Code Slack team’s PowerCLI channel: https://code.vmware.com/slack/

New Release: vSphere PowerCLI 5.5 R2

image

I am pleased to announce that vSphere PowerCLI 5.5 R2 has now been released and has some great new features.  In this release we take PowerCLI one step further and allow even more troubleshooting, reporting and automation of vCloud Suite products by introducing easy access to vCenter Site Recovery Manager (SRM) APIs through the core PowerCLI cmdlets.

 

Why wait, download the latest version today from here.

vSphere PowerCLI 5.5 Release 2 introduces the following new features and improvements, for a full list of all that has changed please check the full vSphere PowerCLI 5.5 R2 Release notes here.

Full management of the vCenter SRM Public API

Using the Connect-SRMServer and Disconnect-SRMServer you are now able to connect to vCenter SRM and access
all public APIs available, use of the $global:DefaultSrmServers object properties and methods after connection allow for access to recovery group and protection group automation, see the built in help and examples for more information and watch out for future posts with more information on this site.

Support for creating and removing Tags and Tag Categories

Enhancing the cmdlets from the previous version of PowerCLI we are now able to use PowerCLI for complete Tag management with the added New/Set/Remove Tag and TagCategory cmdlets.

Enable/Retrieve information on EVC Mode for Clusters

Adjustments to the Host and Cluster Cmdlets now allow for enabling, disabling and retrieving information for EVC Mode making automated build environments one step easier to accomplish.

Security policies for vSphere standard switch and port groups

Security policies can now be easily adjusted on vSphere standard switches and portgoups using the Get/Set-SecurityPolicy cmdelts.

Added support for PowerShell 4.0

PowerCLI can now be installed and used with the latest version of PowerShell at this time, PowerShell 4.0

Added support for IPv6

PowerCLI has now been updated to support vSphere servers configured with IPv6

Added statistical information

PowerCLI has been updated and we have added the ability to specify all supported types including clusters, datastores, etc and retrieve more statistical information via the Get-Stat and Get-StatType cmdlets.

64 bit Support

The New/Set-OSCustomizationSpec cmdlets have been updated to work in 64-bit PowerShell and no longer require running in a 32-bit PowerShell environment.

Even more updates

The above list is a high level list of the updates made to vSphere PowerCLI, for a more comprehensive list including all parameter and functional improvements, security enhancements, and deprecated features, see the vSphere PowerCLI Release Notes and the vSphere PowerCLI Change Log.

For more information on specific product features, see the VMware vSphere PowerCLI 5.5 Release 2 User’s Guide.

For more information on specific cmdlets, see the VMware vSphere PowerCLI 5.5 Release 2 Cmdlet Reference.

Download and Install PowerCLI 5.5 Release 2 today from here.

New Book: Learning PowerCLI

Everyone I meet sees the time that PowerCLI can save you by automating your day to day tasks, easily creating reports, troubleshooting your environment and much more but to use PowerCLI you first need to take the time to learn it, this can be achieved in a variety of methods but still the most popular is reading a book and putting it into practice.

If you are the reading kind of person then make sure you check out the existing PowerCLI Library of books:

 

Learning PowerCLI

There is a new book now available with the latest up to date information, it was written specifically with the vSphere Admin in mind and shows how you can easily get started using PowerCLI.  The book was written by community member Robert van den Nieuwendijk and published by PACKT.

The book is available in all good book stores and online book retailers such as with Amazon here.  Whats more you can take a look inside the book to see if its for you here.

What you will learn from this book

    • Download and install PowerCLI
    • Add hosts to VMware vCenter Server
    • Configure vSphere Auto Deploy
    • Use the esxcli command from PowerCLI
    • Create OS Customization Specs
    • Monitor virtual machine performance
    • Configure distributed virtual switches and storage I/O Control
    • Enable VM and Application Monitoring
    • Manage licenses for multiple hosts to migrate them easily
    • Configure an alarm to monitor your networks virtual machines
    • Generate a good-looking HTML report in no time

Win a copy

PACKT and Robert were kind enough to give VMware 5 copies of the book to give away here, in order to win a copy all you need to do is add a comment to this site (make sure you include your email address) telling us why you need to learn PowerCLI.

Entries will be judged by Robert and chosen by March 14th 2014, once chosen you will receive an email with a link to receive your copy of the book.

Good Luck.