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.


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.


12 comments have been added so far

  1. Hello,

    I left comment in the previous post but mistyped the name of the script.
    Does anyone you know why the custom script does not run with the new Power CLIversion – Initialize-PowerCLIEnvironment_Custom.ps1?
    I have moved the script to the new folder but still not running. According to the documentation there were no changes of the way it should run.


    1. @Nasko

      The location of the initialization script is: C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts dot sourcing this works for me.

      Why do you need to use this and not the suggested method above?

      1. Hi Alan,
        Many thanks for the prompt reply.
        I confirm that I am using the same location for my Initialize-PowerCLIEnvironment_Custom.ps1 script but is not started at all.
        I use the script to save my time and connect to all Virtual centers automatically:
        Connect-VIServer -Server
        Connect-VIServer -Server
        Connect-VIServer -Server
        and also for some additional shell configs.
        According to the documentation, if I start my PowerCLI, it will run my _Custom.ps1 script from the location you mentioned – C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts but in practice, when I used Process Monitor ( it never at this location for script with _Custom.ps1 name. The only location it is looking for a script with that name is C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Sdk but when I move the script there it doesn’t work as the modules are not yet loaded.
        The issue above is applicable for Windows 7.

        1. Nasco, did you ever get this working? I am having the same issue as you, and I use the _Custom file for the same reason as you too.

          Alan, have you heard of other people running into this same issue?

          1. Hi Ray,
            I haven’t had any feedback from VMware :-(.
            As wokraround I have created script with my custom commands and run it manually every time when I start PowerCLI.
            Hopefully, it will be fixed in the next release…….


  2. Wow, this is such a big improvement in VMware PowerCLI 6.5 R1 release . Finally PowerShell snapins has gone. VMware PowerCLI moving over to be completely modules is a huge accomplishment in this newest release. Thanks for sharing this good news .I have really enjoyed your article. Now I am thinking to upgrade our PowerCLI . Thanks for sharing the download link of PowerCLI 6.5 Release 1 .

  3. Hi, guys.
    Thanks for new PowerCLI 6.5 R1 release.

    I want to share next tiny script block for importing PowerCLI Modules (should be backward compatible with previous PowerCLI versions where snap-ins were available):
    #Import VMware PowerShell snap-ins or modules to the current session
    Write-Verbose -Message “Importing VMware automatation snap-in” -Verbose
    $VmwareAutoSnap=Get-PSSnapin -Name VM* -Registered -ErrorVariable +err_snap -ErrorAction SilentlyContinue
    if (!$err_snap)
    $VmwareAutoSnap|Add-PSSnapin -ErrorAction Stop
    else {
    Write-Verbose -Message “VMware automatation snap-ins were not registered (probably PowerCLI was not installed) or you have PowerCLI version 6.5R1 and later installed (where only Modules are available).” -Verbose
    $VmwareAutoModules=Get-Module -Name VM* –ListAvailable -ErrorAction Stop
    if ($VmwareAutoModules)
    Write-Verbose -Message “Trying to load VMware automatation modules.” -Verbose
    $VmwareAutoModules|Import-Module -ErrorAction Stop
    else {
    Write-Verbose -Message “VMware automatation modules are not available (probably PowerCLI was not installed).” -Verbose
    Write-Error -Message “Failed importing either VMware automatation snap-ins or VMware automatation modules” -Verbose
    Write-Error -Message $_ -Verbose

  4. Kyle/Alan, Thank you for pointing me to this blog article.

    Andrii, Nice script. I think this would work for most PowerCLI scripts that use crore cmdlets. However, one thing I noticed is that on a machine with PowerCLI 6.3 installed, it will initialize the following modules:
    Binary VMware.VimAutomation.Cis.Core {Connect-CisServer, Disconnect-CisServer, Get-CisService}
    Manifest VMware.VimAutomation.Common
    Manifest VMware.VimAutomation.Sdk

    A PowerCLI shell will initialize a larger list of modules:
    Binary VMware.VimAutomation.Cis.Core {Connect-CisServer…
    Binary VMware.VimAutomation.Cloud {Add-CIDatastore, …
    Manifest VMware.VimAutomation.Common
    Script VMware.VimAutomation.Core
    Binary VMware.VimAutomation.HA Get-DrmInfo
    Binary VMware.VimAutomation.License Get-LicenseDataMan…
    Binary VMware.VimAutomation.PCloud {Connect-PIServer,…
    Manifest VMware.VimAutomation.Sdk
    Binary VMware.VimAutomation.Storage {Export-SpbmStorag…
    Binary VMware.VimAutomation.Vds {Add-VDSwitchPhysi…
    Binary VMware.VimAutomation.vROps {Connect-OMServer,…
    Binary VMware.VumAutomation {Add-EntityBaselin…

    If I run your script on a machine with PowerCLI 6.5 installed, a full inventory of modules is initialized:
    Binary VMware.DeployAutomation {Add-DeployRule, Add-ProxyServer, Add-ScriptBundle, Copy-DeployRule…}
    Binary VMware.ImageBuilder {Add-EsxSoftwareDepot, Add-EsxSoftwarePackage, Compare-EsxImageProfile, …
    Binary… VMware.VimAutomation.Cis.Core {Connect-CisServer, Disconnect-CisServer, Get-CisService}
    Binary… VMware.VimAutomation.Cloud {Add-CIDatastore, Connect-CIServer, Disconnect-CIServer, Get-Catalog…}
    Manifest… VMware.VimAutomation.Common
    Binary… VMware.VimAutomation.Core {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAdapter, Add-VMH…
    Binary VMware.VimAutomation.HA Get-DrmInfo
    Binary… VMware.VimAutomation.HorizonView {Connect-HVServer, Disconnect-HVServer}
    Binary… VMware.VimAutomation.License Get-LicenseDataManager
    Binary… VMware.VimAutomation.PCloud {Connect-PIServer, Disconnect-PIServer, Get-PIComputeInstance, Get-PIDat…
    Manifest… VMware.VimAutomation.Sdk Get-PSVersion
    Binary… VMware.VimAutomation.Storage {Copy-VDisk, Export-SpbmStoragePolicy, Get-NfsUser, Get-SpbmCapability…}
    Binary… VMware.VimAutomation.Vds {Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, Export-VDPortGr…
    Binary… VMware.VimAutomation.vROps {Connect-OMServer, Disconnect-OMServer, Get-OMAlert, Get-OMAlertDefiniti…
    Binary VMware.VumAutomation {Add-EntityBaseline, Copy-Patch, Get-Baseline, Get-Compliance…}

  5. There’s a problem with this new methodology.

    One has to run Import-Module VMware.VimAutomation.Core every single time Powershell is launched.

    Behavior is as follows, on Windows 10 Enterprise Version 1803 (latest build as of 6/12/2018).
    1) Launch Powershell shell (I use Powershell ISE)
    2) Check the available commands on the right-side panel under “VMware.VimAutomation.Core”. The only thing in the list is “HookGetViewAutoCompleter”.
    3) Run “Import-Module VMware.VimAutomation.Core” and refresh the list….all the commands are there – great ! Starts with Add-PassthroughDevice and ends with Wait-Tools
    4) Close ISE window and relaunch. Command list looks identical to step 2.

    So far, I’ve been unable to find a workaround. It isn’t a big deal, I just have to inclue “Import-Module VMware.VimAutomation.Core” in any vSphere-related PS script I write.

    Anybody have a better workaround that makes the command list stick?


    1. PowerCLI supports the auto-importing of modules into PowerShell assuming that you’re on PowerShell 3.0 or greater.

      To pre-populate ISE, you could add that import-module command to your PowerShell Profile for ISE.

      Script wise, there shouldn’t be any need to add that import-module command to your script. The required PowerCLI modules will auto-import as soon as they’re called at the command line.

Leave a Reply

Your email address will not be published.