Home > Blogs > VMware PowerCLI Blog


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.

This entry was posted in General and tagged , , , on by .
Kyle Ruddy

About Kyle Ruddy

Kyle Ruddy is a Senior Technical Marketing Engineer at VMware in the Cloud Platform Business Unit. Kyle currently focuses on vSphere with Operations Management as well as all things API, SDK, and CLI. Kyle can be found blogging on VMware blogs, http://blogs.vmware.com/vSphere and http://blogs.vmware.com/PowerCLI, and his personal blog, http://www.thatcouldbeaproblem.com. You can follow Kyle on twitter as @kmruddy.

11 thoughts on “Saying Farewell to Snapins!

  1. Nasko

    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.

    Thanks!

    Reply
    1. Alan Renouf

      @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?

      Reply
      1. Nasko

        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 vc1.domain.com
        Connect-VIServer -Server vc2.domain.com
        .
        Connect-VIServer -Server vcn.domain.com
        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 (https://technet.microsoft.com/en-us/sysinternals/processmonitor.aspx) 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.
        Thanks!

        Reply
        1. Ray Holtz

          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?

          Reply
          1. Nasko

            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…….

            Thanks!

  2. Rahul

    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 .

    Reply
  3. Pingback: Saying Farewell to Snapins! – VMpro.at

  4. Andrii

    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
    try{
    $err_snap=$null
    $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
    Return
    }
    }
    }
    catch{
    Write-Error -Message “Failed importing either VMware automatation snap-ins or VMware automatation modules” -Verbose
    Write-Error -Message $_ -Verbose
    }
    ##################################

    Reply
  5. Jason Boche

    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 6.0.0.0 VMware.VimAutomation.Cis.Core {Connect-CisServer, Disconnect-CisServer, Get-CisService}
    Manifest 6.3.0.0 VMware.VimAutomation.Common
    Manifest 6.3.0.0 VMware.VimAutomation.Sdk

    A PowerCLI shell will initialize a larger list of modules:
    Binary 6.0.0.0 VMware.VimAutomation.Cis.Core {Connect-CisServer…
    Binary 6.3.0.0 VMware.VimAutomation.Cloud {Add-CIDatastore, …
    Manifest 6.3.0.0 VMware.VimAutomation.Common
    Script 6.3.0.0 VMware.VimAutomation.Core
    Binary 6.0.0.0 VMware.VimAutomation.HA Get-DrmInfo
    Binary 1.0.0.0 VMware.VimAutomation.License Get-LicenseDataMan…
    Binary 6.0.0.0 VMware.VimAutomation.PCloud {Connect-PIServer,…
    Manifest 6.3.0.0 VMware.VimAutomation.Sdk
    Binary 6.0.0.0 VMware.VimAutomation.Storage {Export-SpbmStorag…
    Binary 6.3.0.0 VMware.VimAutomation.Vds {Add-VDSwitchPhysi…
    Binary 6.3.0.0 VMware.VimAutomation.vROps {Connect-OMServer,…
    Binary 6.0.0.0 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 6.0.0.0 VMware.DeployAutomation {Add-DeployRule, Add-ProxyServer, Add-ScriptBundle, Copy-DeployRule…}
    Binary 6.0.0.0 VMware.ImageBuilder {Add-EsxSoftwareDepot, Add-EsxSoftwarePackage, Compare-EsxImageProfile, …
    Binary 6.5.0.4… VMware.VimAutomation.Cis.Core {Connect-CisServer, Disconnect-CisServer, Get-CisService}
    Binary 6.5.0.4… VMware.VimAutomation.Cloud {Add-CIDatastore, Connect-CIServer, Disconnect-CIServer, Get-Catalog…}
    Manifest 6.5.0.4… VMware.VimAutomation.Common
    Binary 6.5.0.2… VMware.VimAutomation.Core {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAdapter, Add-VMH…
    Binary 6.0.0.0 VMware.VimAutomation.HA Get-DrmInfo
    Binary 7.0.2.4… VMware.VimAutomation.HorizonView {Connect-HVServer, Disconnect-HVServer}
    Binary 6.5.0.4… VMware.VimAutomation.License Get-LicenseDataManager
    Binary 6.5.0.4… VMware.VimAutomation.PCloud {Connect-PIServer, Disconnect-PIServer, Get-PIComputeInstance, Get-PIDat…
    Manifest 6.5.0.4… VMware.VimAutomation.Sdk Get-PSVersion
    Binary 6.5.0.4… VMware.VimAutomation.Storage {Copy-VDisk, Export-SpbmStoragePolicy, Get-NfsUser, Get-SpbmCapability…}
    Binary 6.5.0.4… VMware.VimAutomation.Vds {Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, Export-VDPortGr…
    Binary 6.5.0.4… VMware.VimAutomation.vROps {Connect-OMServer, Disconnect-OMServer, Get-OMAlert, Get-OMAlertDefiniti…
    Binary 6.0.0.0 VMware.VumAutomation {Add-EntityBaseline, Copy-Patch, Get-Baseline, Get-Compliance…}

    Reply
  6. good morning

    Hmm it seems like your website ate my first comment (it was super long) so I guess I’ll just sum it up what
    I had written and say, I’m thoroughly enjoying your blog.
    I as well am an aspiring blog blogger but I’m still new to everything.
    Do you have any recommendations for beginner blog writers?
    I’d genuinely appreciate it.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*