profile for Gajendra D Ambi on Stack Exchange, a network of free, community-driven Q&A sites

Monday, May 23, 2016

Load Powercli with Powershell on launch

You might have noticed that once you run the following


Import-Module VMware.VimAutomation.Core     -ErrorAction SilentlyContinue
Import-Module VMware.VimAutomation.Vds      -ErrorAction SilentlyContinue
Import-Module VMware.VimAutomation.Cis.Core -ErrorAction SilentlyContinue
Import-Module VMware.VimAutomation.Storage  -ErrorAction SilentlyContinue
Import-Module VMware.VimAutomation.vROps    -ErrorAction SilentlyContinue
Import-Module VMware.VimAutomation.HA       -ErrorAction SilentlyContinue
Import-Module VMware.VimAutomation.License  -ErrorAction SilentlyContinue
Import-Module VMware.VimAutomation.Cloud    -ErrorAction SilentlyContinue
Import-Module VMware.VimAutomation.PCloud   -ErrorAction SilentlyContinue
Import-Module VMware.VumAutomation          -ErrorAction SilentlyContinue

in your powershell or powershell ISE you will see the vmware commands and modules but when you re launch the powershell or it's ISE they are gone again. So the importing of these things is not permanent.
Go ahead and run the following

Test-Path $Profile
 and if it returns false then you have to create a new profile but if it returns true then directly go to the step where you have to edit it.

New-Item -path $profile -type file -force
 Now you can go ahead and edit it to add the above entries to import VMware modules.

Notepad $Profile
 Now, just copy paste the above lines starting with Import-Module and save it. Restart your powershell or powershell ISE and you will have your VMware cmdlts and modules always loaded and ready. When I get time I will try to get a script created for this too but for now, this will do.