Automation

 View Only
Expand all | Collapse all

running powercli command on powershell

  • 1.  running powercli command on powershell

    Posted Oct 02, 2017 06:33 PM

    Hi All,

    What is the easiest way to run powercli (6.5) on powershell ISE(5.0)

    any help is much appreciated.



  • 2.  RE: running powercli command on powershell

    Posted Oct 02, 2017 07:36 PM

    When you have PowerCLI 6.5.1, or later, installed from the PowerShell Gallery, in principle you will not have to do anything.

    The PowerShell auto-load feature will load the required module automatically when you type the first cmdlet from that module.

    As a test, make sure no modules are imported.

    Start the ISE, then type for example 'Connect-', the Intellisense feature will show you all the possible cmdlets.

    That is achieved through the auto-loading feature.



  • 3.  RE: running powercli command on powershell

    Posted Oct 03, 2017 11:21 AM

    Hello Luc,

    Thanks for your response but it was not installed from powershell gallery.

    however there is some discussion about editing following two profile files.

    # Load Windows PowerShell cmdlets for managing vSphere

    Add-PsSnapin VMware.VimAutomation.Core -ea "SilentlyContinue"

    but above does not work .could you comment on above process if that can be made working in case something is missing .



  • 4.  RE: running powercli command on powershell

    Posted Oct 03, 2017 01:12 PM

    The PowerCLI versions before 6.5R1 were a combination of PSSnapin and Modules, you will have to load all of those, at least the ones you are planning to use cmdlets from.

    I posted one way of doing that in Universal PowerCLI Loader



  • 5.  RE: running powercli command on powershell

    Posted Oct 03, 2017 05:03 PM

    Thanks Iam checking this.



  • 6.  RE: running powercli command on powershell

    Posted Oct 03, 2017 03:11 PM

    Hello, You can try this instead - Import-module vmware.vimautomation.core This works fine for me.

    --------

    Branav.



  • 7.  RE: running powercli command on powershell

    Posted Oct 03, 2017 04:33 PM

    That only loads 1 module, and ignores the PSSnapin.



  • 8.  RE: running powercli command on powershell

    Posted Oct 03, 2017 05:09 PM

    Hi Branav,

    thnaks for replying .i imported the module and checking to import other modules also .



  • 9.  RE: running powercli command on powershell

    Posted Oct 03, 2017 05:43 PM

    Hello JVM,

    Just a guess, but haven't tried this before. Not in front of my pc now to give a try though.

    Right click powercli shortcut icon > properties > General tab > location - it should be pointing to some .psm1 file. We can try running that .psm1 file from powershell.



  • 10.  RE: running powercli command on powershell

    Posted Oct 03, 2017 05:47 PM

    Afaik, the PowerCLI shortcut, which is not used anymore, was pointing to an init script (.ps1), not a module (.psm1)



  • 11.  RE: running powercli command on powershell

    Posted Oct 04, 2017 01:01 AM

    Hello Luc,

    That is correct, It was .ps1 file. My bad memory :smileysad:

    But, I can still see shortcut for Powercli 6.5. And the shortcut is pointing to "C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1".

    I tried running Initialize-PowerCLIEnvironment.ps1 from powershell, It works like charm.



  • 12.  RE: running powercli command on powershell

    Posted Oct 04, 2017 01:09 AM

    Hello JVM,

    Eaiset way to accomplish your goal is execute the below .ps1 file in powershell.

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

    Or alternative way is to save the below content in .ps1 file and execute it from powershell window.

    Import-module VMware.VimAutomation.Core

    Import-module VMware.VimAutomation.Vds

    Import-module VMware.VimAutomation.Cloud

    Import-module VMware.VimAutomation.PCloud

    Import-module VMware.VimAutomation.Cis.Core

    Import-module VMware.VimAutomation.Storage

    Import-module VMware.VimAutomation.HorizonView

    Import-module VMware.VimAutomation.HA

    Import-module VMware.VimAutomation.vROps

    Import-module VMware.VumAutomation

    Import-module VMware.DeployAutomation

    Import-module VMware.ImageBuilder

    Import-module VMware.VimAutomation.License

    I have tried both methods, And it works. :smileyhappy:



  • 13.  RE: running powercli command on powershell

    Posted Oct 04, 2017 04:43 AM

    Using Initialize-PowerCLIEnvironment.ps1 is a bad habit, since starting with 6.5.1 that .ps1 doesn't exist anymore.

    Only running Import-Module doesn't take into account that the requestor's version also contains PSSnapin.



  • 14.  RE: running powercli command on powershell

    Broadcom Employee
    Posted Oct 04, 2017 06:10 AM

    jvm2016

    After installing powercli 6.5, modified the file Microsoft.PowerShellISE_profile.ps1 to include the below contents :

    # Load Windows PowerShell with cmdlets for managing vSphere

    Import-Module VMware.PowerCLI


    This auto loaded all the powercli cmdlets into powershell ISE.

    Location of file : C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1



  • 15.  RE: running powercli command on powershell

    Posted Oct 05, 2017 07:21 PM

    So...

    maybe i am wrong. But i think i had the same problems days ago.

    You need to put the modules into the module path and the will be load automatic.

    Show wich module pathes you have

    $env:PSModulePath

    Add new Location to the module path:

    $env:PSModulePath = $env:PSModulePath + ";c:\ModulePath"

    To fix this you can put this line in your Profile file.

    Than you can use all the modules with the Auto load feature.

    Sry if i missed something important.