简体   繁体   中英

Get-VICommand works in PowerCLI, but not recognized in Windows PowerShell ISE

I am using VMware vSphere PowerCLI, and in order to run Get-VICommand (as well as many other PowerCLI commands), I must launch the program with administrator privileges. However, if I type ise in PowerCLI to launch Windows PowerShell ISE, and then try and run Get-VICommand from ISE, the command will not work. I have tried manually launching Windows PowerShell ISE as administrator, but I get the same results.

Has anyone run into this problem and found a way to fix it? For now I can just run all of my commands from PowerCLI, but I would prefer to be able to use ISE, especially for writing long scripts that span dozens of lines.

I am running on Windows 7 if that helps.

You need to have the PowerCLI modules loaded in the ISE. It depends on the version of PowerCLI you are running as to how you do it. To start just try and run Get-Module -ListAvailable or Get-Module -ListAvailable VM* If you can see the VMware modules you should be able to just do import-module

Othwerwise you need to get the modules setup,

This can be done a few ways, Seems like running this line is popular:

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

This is called dot sourcing, It will load the script following the . in to your current script on execution.

Adding the path to the modules folder will probably be a good idea as well:

$path = [Environment]::GetEnvironmentVariable("PSModulePath")
$path += ";C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\"
[Environment]::SetEnvironmentVariable("PSModulePath",$path)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM