Automation

 View Only
Expand all | Collapse all

Get-VICommand does not work

  • 1.  Get-VICommand does not work

    Posted Oct 20, 2011 10:25 PM

    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.



  • 2.  RE: Get-VICommand does not work

    Posted Oct 21, 2011 12:54 PM

    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



  • 3.  RE: Get-VICommand does not work

    Posted Oct 21, 2011 04:08 PM

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



  • 4.  RE: Get-VICommand does not work

    Posted Oct 21, 2011 04:19 PM

    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?



  • 5.  RE: Get-VICommand does not work

    Posted Oct 21, 2011 06:55 PM

    I counted 236 lines

    and Get-PowerCLIVersion returns 4.1 build 264274



  • 6.  RE: Get-VICommand does not work

    Posted Oct 21, 2011 01:17 PM

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



  • 7.  RE: Get-VICommand does not work

    Posted Oct 21, 2011 01:38 PM

    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.



  • 8.  RE: Get-VICommand does not work

    Posted Oct 21, 2011 01:39 PM

    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.



  • 9.  RE: Get-VICommand does not work

    Posted Oct 21, 2011 02:01 PM

    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.



  • 10.  RE: Get-VICommand does not work

    Posted Oct 21, 2011 02:54 PM

    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



  • 11.  RE: Get-VICommand does not work
    Best Answer

    Posted Oct 21, 2011 05:23 PM

    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)


  • 12.  RE: Get-VICommand does not work

    Posted Oct 21, 2011 06:58 PM

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



  • 13.  RE: Get-VICommand does not work

    Posted Oct 21, 2011 05:56 PM

    # Set-ExecutionPolicy Unrestricted

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

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