Adding VMware PowerCLI to your standard PowerShell environment

In order to get access to PowerCLI when using another PowerShell shortcut or environment you can run the following commands which is what happens when you run the VMware provided shortcut.

# Adds the base cmdlets
Add-PSSnapin VMware.VimAutomation.Core
# Add the following if you want to do things with Update Manager
Add-PSSnapin VMware.VumAutomation
# This script adds some helper functions and sets the appearance. You can pick and choose parts of this file for a fully custom appearance.
. "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-VIToolkitEnvironment.ps1"

**UPDATE 2/7/2013**
As Paul noted in the comments, the new initialization script is called Initialize-PowerCLIEnvironment.ps1. Also, if you are on a 64 bit system the files will be in “Program Files (x86)”

Note on the last line that there is a space between the “.” and the path to the script. That space is very important as it means we are including or “dot sourcing” the file.

If you want this all to load every time you launch PowerShell you can add these commands to your profile startup scripts. This is a great place to add functions or aliases that you use all the time. The profile is run once when the PowerShell environment is launched.

Comments (9)

  1. Paul Grevink

    Hi Eric,

    Thank you very much, this was very useful. Today Initialize-VIToolkitEnvironment.ps1 has been replaced by Initialize-PowerCLIEnvironment.ps1

    Best regards,

    Paul

  2. Bill bukowski

    This was great but thought to add as well. For windows 8 64bit this is what my code looks like when I add it to the profile. I noticed you were missing the (x86) bit.

    . “C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1”

  3. Chris

    The 2nd command doesn’t work. It cant find the snap-in:

    PowerCLI C:\Windows\system32> Add-PSSnapin VMware.VimAutomation.Core

    PowerCLI C:\Windows\system32> Add-PSSnapin VMware.VumAutomation
    Add-PSSnapin : The Windows PowerShell snap-in ‘VMware.VumAutomation’ is not installed on this computer.
    At line:1 char:1
    + Add-PSSnapin VMware.VumAutomation
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (VMware.VumAutomation:String) [Add-PSSnapin], PSArgumentExcep
    tion
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

  4. Eric (Post author)

    @Chris You have to make sure that you install the Update Manager Cmdlets

    https://communities.vmware.com/community/vmtn/automationtools/powercli/updatemanager

  5. Kenny

    The 2nd command doesn’t work because it contains a typo – “VumAuto…” should be “VimAuto… (the first ‘u’ in the former should be an ‘i’).

    And for the newer version(s) of PowerCLI, there’s no “VMware.VimAutomation” snap-in anyways. The PowerShell console file that the PowerCLI console uses includes another snap-in “VMware.VimAutomation.Vds” instead.

  6. Arthor Dent

    Chris the snapin VMware.VumAutomation is for the VMware Update Manager and you have to have the update manager CLI installed for it to work.

  7. Masat

    Hi,

    Do you know how to remove “PowerCLI” which is in front of set-location(C:\) ?

  8. Pingback: Adding VMware PowerCLI to your standard PowerShell environment – VMDK 教室

  9. Mastan

    Hello

    How to load powercli modules for powercli version 5.5?

Leave a Comment

Your email address will not be published.