Skip to content

How to properly initialize PowerCLI 6.x in PowerShell ISE

With the release of vSphere 6.0 VMware has started to transform their distribution model of PowerCLI cmdlets from PSSnapins into modules. This is a good thing because modules are the preferred method of adding cmdlets to PowerShell. Unfortunately the changed behavior breaks plenty instructions on how to load VMware PowerCLI in ISE, including my own. The old method works for core cmdlets, but functions related to Distributed Switches or Storage Policies for example are missing.

If you have the latest version of PowerCLI installed but cmdlets are missing in PowerShell ISE, maybe you are using the old method to load cmdlets.

Get-VDSwitch : The term 'Get-VDSwitch' is not recognized as the name of a cmdlet, function, script file, or operable program.

Do no longer use this command in Microsoft.PowerShellISE_profile.ps1
Add-PsSnapin VMware.VimAutomation.Core -ea "SilentlyContinue"

It will only load the Snapin:
get-pssnapin-vnware

...not the Modules...
get-module-vnware

...which results in the following cmdlets to be missing:

VMware.VimAutomation.HA
Get-DrmInfo

VMware.VimAutomation.License
Get-LicenseDataManager

VMware.VimAutomation.PCloud
Connect-PIServer, Disconnect-PIServer, Get-PIComputeInstance, Get-PIDatacenter

VMware.VimAutomation.Storage
Export-SpbmStoragePolicy, Get-NfsUser, Get-SpbmCapability, Get-SpbmCompatibleStorage, Get-SpbmEntityConfiguration, Get-SpbmStoragePolicy, Get-VAIOFilter, Get-VasaProvider, Get-VasaStorageArray, Get-VsanDisk, Get-VsanDiskGroup, Import-SpbmStoragePolicy, New-NfsUser, New-SpbmRule, New-SpbmRuleSet, New-SpbmStoragePolicy, New-VAIOFilter, New-VasaProvider, New-VsanDisk, New-VsanDiskGroup, Remove-NfsUser, Remove-SpbmStoragePolicy, Remove-VAIOFilter, Remove-VasaProvider, Remove-VsanDisk, Remove-VsanDiskGroup, Set-NfsUser, Set-SpbmEntityConfiguration, Set-SpbmStoragePolicy, Set-VAIOFilter

VMware.VimAutomation.Vds
Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, Export-VDPortGroup, Export-VDSwitch, Get-VDBlockedPolicy, Get-VDPort, Get-VDPortgroup, Get-VDPortgroupOverridePolicy, Get-VDSecurityPolicy, Get-VDSwitch, Get-VDSwitchPrivateVlan, Get-VDTrafficShapingPolicy, Get-VDUplinkLacpPolicy, Get-VDUplinkTeamingPolicy, New-VDPortgroup, New-VDSwitch, New-VDSwitchPrivateVlan, Remove-VDPortGroup, Remove-VDSwitch, Remove-VDSwitchPhysicalNetworkAdapter, Remove-VDSwitchPrivateVlan, Remove-VDSwitchVMHost, Set-VDBlockedPolicy, Set-VDPort, Set-VDPortgroup, Set-VDPortgroupOverridePolicy, Set-VDSecurityPolicy, Set-VDSwitch, Set-VDTrafficShapingPolicy, Set-VDUplinkLacpPolicy, Set-VDUplinkTeamingPolicy, Set-VDVlanConfiguration

VMware.VimAutomation.vROps
Connect-OMServer, Disconnect-OMServer, Get-OMAlert, Get-OMAlertDefinition, Get-OMAlertSubType, Get-OMAlertType, Get-OMRecommendation, Get-OMResource, Get-OMStat, Get-OMStatKey, Get-OMUser, Set-OMAlert

To load PowerCLI properly, use the the Initialize-PowerCLIEnvironment.ps1 script located at C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts (delivered with the installer).

  1. Open PowerShell ISE
  2. Create and open your profile with:
    New-Item -Path $Profile -ItemType file -Force
    notepad $profile
  3. Notepad will open with an empty file. Enter the following command:

    PowerCli 6.0:

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

    PowerCli 6.5:

    & 'C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'
  4. Restart PowerShell ISE

load-powercli6-in-powershell-ise

Please note that this might be not best practise for everyone. If you are using PowerCLI ISE with small prepared snippets for your daily administration like me, its fine. If you want to write and distribute comprehensive scripts its better to make the script to load the correct module.

3 thoughts on “How to properly initialize PowerCLI 6.x in PowerShell ISE”

  1. Instead '&' you can use 'dot sourcing"

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

  2. For powercli 6.5, correct path for windows 10 is 'C:\Program Files(x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'

Leave a Reply

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