PowerCLI 6.5.1 Tips
- Why should I move to 6.5.1?
- How do I remove all PowerCLI modules?
- How do I get rid of the “Welcome to VMware PowerCLI!” message?
- Listing VMware.PowerCLI as a required module in my module manifest doesn’t work?
Why should I move to 6.5.1?
Three quick reasons:
1. PowerShell Gallery > .msi installation
The prospect of simple updates (
Update-Module) helps encourage VMware to increase the PowerCLI release cadence. Faster updates = quicker bug fixes for us.
It also allows decoupling of the various modules, so a single module could potentially receive a very quick bug fix in the future. If just the
Vds module shipped with a simple bug, previously you’d have to wait months for it to be rolled into the next big PowerCLI release. That’s no longer necessary.
Making the modules available on the gallery also enables community projects to very simply define PowerCLI as a dependency. (cough Vester cough)
2. Implicit module loading
Import-Module VMware.VimAutomation.Core Connect-ViServer vcenter.domain.me
Connect-ViServer vcenter.domain.me # VMware.VimAutomation.Core is automatically loaded
3. It’s backwards compatible
So just do it. :)
How do I remove all PowerCLI modules?
You can download all PowerCLI modules from the PS Gallery with the command
Install-Module VMware.PowerCLI. The VMware.PowerCLI “metapackage” lists 17 PowerCLI modules as
RequiredModules, and automatically installs them as well.
That all works smoothly. But what if you need to uninstall your 18 PowerCLI modules?
Logically, you would
Uninstall-Module VMware.PowerCLI…but that only uninstalls the parent module, and not any of its 17 dependencies. It turns out that this is a current limitation that Microsoft would like to solve. (PowerShellGet #114 for more info.)
In the meantime, though, you can do this:
Get-Module vmware* -ListAvailable | Uninstall-Module -Force
How do I get rid of the “Welcome to VMware PowerCLI!” message?
When you manually
Import-Module VMware.PowerCLI into your current session, you’re greeted with a welcome message. Friendly, perhaps, but some users are just trying to write results to a log file, and don’t want it included.
Short answer: Do not
Import-Module VMware.PowerCLI. This manually imports 17 modules, and it’s a waste of time when implicit module loading should cover you. In most cases, you only want
VMware.VimAutomation.Core and maybe a second module.
VMware.PowerCLIis just a method to group all VMware modules together. By itself, it does virtually nothing. Aside from optionally using it to install all modules from the gallery at once, you shouldn’t need to refer specifically to it.
Let’s walk through the long answer together. If I still want to import everything, is it possible to suppress that message?
# Receive a welcome message, and load 17 PowerCLI modules into your session Import-Module VMware.PowerCLI # Ok. Well maybe I can suppress the welcome message # Let's open up the module definition in the ISE ise (Get-Module VMware.PowerCLI).Path # No "ModuleToProcess" defined # But scrolling down, we do find "NestedModules= @('VMware.PowerCLI.ps1')" ise "$((Get-Module VMware.PowerCLI).ModuleBase)\VMware.PowerCLI.ps1"
Write-Host. I don’t recommend that you solve this problem by editing this file…it’ll just come back next update. Don’t hack the source code for such a simple fix. Solve it the easy way: Not manually importing the parent module.
vmkdaily also wrote about this process: Controlling the PowerCLI Welcome Message.
Listing VMware.PowerCLI as a required module in my module manifest doesn’t work?
PowerShell modules usually have “module manifest” (
.psd1) files. One benefit of this is the ability to specify “RequiredModules”. As mentioned above,
VMware.PowerCLI has 17 RequiredModules. This means two things:
- When installing the module from the PS Gallery, all requirements are also downloaded and installed
- When importing the module into your current PS session, all requirements are also imported
However, if you create a module that lists
VMware.PowerCLI as a requirement, PowerShell throws a “cyclic dependency” error at you:
Import-Module : The required module ‘VMware.VimAutomation.Cis.Core’ is not loaded. The module ‘VMware.VimAutomation.Cis.Core’ has a requiredModule ‘VMware.VimAutomation.Common’ in its module manifest ‘C:\Program Files\WindowsPowerShell\Modules\VMware.VimAutomation.Cis.Core\22.214.171.12474323\VMware.VimAutomation.Cis.Core.psd1’ that points to a cyclic dependency.
This error is a PowerShell bug. It was raised as issue PowerShell #2607, and fixed a month ago by Microsoft. While the fix was applied to PowerShell 6.0-beta1, it probably won’t make it back to PS 5.1.
Again: Don’t require
VMware.PowerCLI. Instead, require the one or two modules actually relevant to the task at hand.
I’m not expecting any additional effort from the PowerCLI team to work around this, but if you care enough to have read this far, your guess is probably better than mine.
If you think I have anything wrong, or you have another question, let me know!