VMWARE VSPHERE POWERCLI INSTALLATION AND CONFIGURATION STEP BY STEP
After installing VMware vSphere PowerCLI installer, when running it for first time you may see below error on the PowerCLI console.
. : File C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1
cannot be loaded because running scripts is disabled on this system. For more information, see
about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:3
+ . "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scri ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
This is due to when we run PowerCLI it try to execute initialize-powerCLIEnvironment.PS1 kept under %program files%\VMware\Infrastructure\vSphere Powercli\Scripts but it fails due to by default powershell scripts PS1 cannot be executed and it is blocked, I can confirm this by running command Get-ExecutionPolicy and I get result as Restricted. Due to this Powercli vmware related commands cannot be executed and you see error. (I am running one of the Get-VM vmware command)
get-vm : The term 'get-vm' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ get-vm
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (get-vm:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
To resolve this open Powershell - Run as administrator and execute below command and type Yes to enable script file execution.
Set-ExecutionPolicy Unrestricted
Next just relaunch Powercli and PowerCLI command environment will be available. and you can use connect-viserver to login into vcenter or Esxi host.