• Blog
  • About
Menu
  • Blog
  • About
Home  /  Virtualization  /  PowerCLI: The term ‘Connect-VIServer’ is not recognized
16 November 2015

PowerCLI: The term ‘Connect-VIServer’ is not recognized

Virtualization PowerShell, tips Leave a Comment

After “upgrading” to Windows 10 with a fresh installation, I was immediately greeted with a lovely error message when attempting to open PowerCLI:

Connect-VIServer : The term 'Connect-VIServer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Connect-VIServer
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Connect-VIServer:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Update: Time heals all wounds. I have yet to figure out what resolved the errors I experienced with PowerCLI, but several days after the installation and it has resolved itself–perhaps an update for Windows indirectly resolved the issue.

Update 2: I have stumbled upon a VMware blog, PowerCLI 6.0 – Introducing PowerCLI Modules, that includes commands that resolves an error with PSModulePath pointing to the user rather than system-wide. Link to commands later in this page.

Resolution

We need to load the VMware PowerShell snap-ins; this can be executed manually each time PowerShell is launched or automatically in each new PowerShell instance.

Manual

Launch a new instance of PowerShell and issue the command:

Add-PSSnapin "VMware.VimAutomation.Core"

This must be performed each time a new PowerShell window is opened.

Automatic

Open the Start Menu and navigate to Programs and search for Windows PowerShell. Right click on the Windows PowerShell shortcut and select Properties. Note: In newer versions of Windows, you may need to select Open File Location from the context menu first to open a File Explorer window with the shortcuts.

Append the Target field with:

 /noexit -Command Add-PSSnapin "VMware.VimAutomation.Core" | Out-Null

Click on the OK button to apply the change. Now every time you launch a new PowerShell instance, the VIM PowerShell snap-in will automatically be loaded. Alternatively, you can duplicate the PowerShell shortcut and rename the new one to Windows PowerShell – VIM to only add the VMware VIM PowerShell snap-in when necessary.

Breaking down the shortcut addition:

/noexit Keeps the PowerShell window open after issuing the following commands
-Command Issues the succeeding command
Out-Null Sounds the output to NULL, effectively hiding the output from the command
Update 2

Execute the following commands in a PowerShell instance.

$p = [Environment]::GetEnvironmentVariable("PSModulePath")
$p += ";C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIModules"
[Environment]::SetEnvironmentVariable("PSModulePath",$p)

Breakdown of the commands:

$p = [Environment]::GetEnvironmentVariable("PSModulePath")
Saves the current value in variable $p
$p += ";C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIModules"
Adds the new path to the variable $p
[Environment]::SetEnvironmentVariable("PSModulePath",$p)
Add the paths in $p to the PSModulePath value

Share On
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit

Leave a Reply Cancel reply