VMware Cloud Community
scbaca
Contributor
Contributor
Jump to solution

Get-VICommand does not work

I go to run the command:

vSphere PowerCLI> Get-VICommand

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

I am on a system that I normally am not on.

0 Kudos
1 Solution

Accepted Solutions
Zsoldier
Expert
Expert
Jump to solution

After installing powercli, when you run the powerCLI shortcut, it calls a ps1 script that adds the snapin.  Running powershell.exe alone does not initialize the snapin by default, unless you've added it to your powershell profile.

The reason the get-vicommand is not working is likely these couple of things:

  1. Execution Policy not set to remotesigned (Set-ExecutionPolicy -RemoteSigned)
  2. The Snap-In was not initialized (Add-PSsnapin VMware.VimAutomation.Core)
Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier

View solution in original post

0 Kudos
12 Replies
nava_thulasi39
Jump to solution

Hi,

You need to use the "get-command" cmdlets to get the commands.

If you want to use very specific commands use like get-command -verb <set>.

Not sure about the get-VIcommand, but I have gone through somewhere. But it never worked in Powercli 4.1

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
0 Kudos
Slingsh0t
Enthusiast
Enthusiast
Jump to solution

I can confirm that get-vicommand does work in powercli 5

0 Kudos
mattboren
Expert
Expert
Jump to solution

Hello, scbaca-

This "command" is a function that is defined in the environment initialization script that comes with PowerCLI.  The current default location for that script is "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1".

The function Get-VICommand uses the standard PowerShell Get-Command cmdlet and adds the (deprecated) -PSSnapin parameter to return just commands from the VMware PSSnapins that are added to the current PowerShell session.  (Microsoft has replaced -PSSnapin with -Module, it seems, but -PSSnapin still works).

So, you could either run that environment initialization script to get the function defined so that you can use Get-VICommand, or you could just use:

## get all commands from VMware.* PSSnapins in current PowerShell session
Get-Command -Module VMware.*

## get all commands from VMware.* PSSnapins in current PowerShell session with a noun matching VMHost*
Get-Command -Module VMware.* -Noun VMHost*

You can use the other standard params for Get-Command, like -Name, -Noun, and -Verb, to narrow your results.  Enjoy.

Zsoldier
Expert
Expert
Jump to solution

That will usually occur when the Snapin hasn't been initialized.

Try running this:

Add-PSsnapin VMware.VimAutomation.Core

Then run the get-vicommand cmdlet.

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
0 Kudos
nava_thulasi39
Jump to solution

Hi Zsoldier,

When we install Powercli, the snapin VMware.VimAutomation.Core will be added default. right?

After installing Powercli -I have modified only Executionpolicy, I never added snapin in Powercli.

If I am wrong, correct me. Thanks in advance.

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
0 Kudos
Slingsh0t
Enthusiast
Enthusiast
Jump to solution

Are you sure you're running Powercli and not just windows powershell from the powercli directory?

To be sure you're running Powershell with the vmware cli snap in enter this in your start>run box:

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -psc "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noe -c ". \"C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\"

Thats for the 32bit version.  Or try running it from the powerCLI desktop icon.  You should see the vmware text load when the powershell window opens.  Then try running get-vicommand

0 Kudos
scbaca
Contributor
Contributor
Jump to solution

Get-command is working, but I have used "on another system" Get-VICommand" no problem.

0 Kudos
Slingsh0t
Enthusiast
Enthusiast
Jump to solution

Please run the following commands:

get-command | ?{$_.ModuleName -like "*vmware*"}

Does this return anything?  If so, how many commands?

get-powercliversion

What does this return?

Zsoldier
Expert
Expert
Jump to solution

After installing powercli, when you run the powerCLI shortcut, it calls a ps1 script that adds the snapin.  Running powershell.exe alone does not initialize the snapin by default, unless you've added it to your powershell profile.

The reason the get-vicommand is not working is likely these couple of things:

  1. Execution Policy not set to remotesigned (Set-ExecutionPolicy -RemoteSigned)
  2. The Snap-In was not initialized (Add-PSsnapin VMware.VimAutomation.Core)
Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
0 Kudos
scbaca
Contributor
Contributor
Jump to solution

# Set-ExecutionPolicy Unrestricted

and I tried running the command: # Add-Snapin....

and it said that the snap-in was already added.

0 Kudos
scbaca
Contributor
Contributor
Jump to solution

I counted 236 lines

and Get-PowerCLIVersion returns 4.1 build 264274

0 Kudos
scbaca
Contributor
Contributor
Jump to solution

Funny thing I restarted the window and it worked right after setting the ExecutionPolicy

0 Kudos