Installing PowerShell/PowerCLI on RHEL 7

By | 21/03/2018

Today I was reading about influxDB and Grafana as I am planning to deploy it in my lab to monitor my vSphere infrastructure and while going through the installation/configuration steps, I stumbled on one step where we needed to have powercli installed on the box where grafana is installed.

Since I am planning to deploy the influxdb/grafana on my centos 7 box, I started looking for how to configure PowerCLI on top of unix variants. Read few articles and finally deployed it my lab.

PowerShell Core v6.0 was released few days ago by Microsoft with support for Windows, Linux, and MacOS. Around same time, VMware released PowerCLI 10.0 which is VMware’s “PowerShell-like” utility. PowerShell version for linux can be downloaded from here

In this post I will be demonstrating installation of both PowerShell and PowerCli Core on RHEL 7 system. If you’re interested in installing this on other variants of linux then please consult this article. PowerCli core can also be installed via docker

All right enough of theory. Lets jump into action and do the deployment. Here are the steps:

1: Add the PowerShell Core repository in YUM Server

[root@mgmt-grafana ~]# curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo

2: Install PowerShell

[root@mgmt-grafana ~]# yum install powershell -y

3: Launch PowerShell session

[root@mgmt-grafana ~]# pwsh
PowerShell v6.0.2
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
PS /root>

4: Verify PowerShell Version

PS /root> $PSVersionTable.PSVersion
Major Minor Patch PreReleas BuildLabel
 eLabel
----- ----- ----- --------- ----------
6 0 2
PS /root>

5: Create trust for PSGallery

Since VMware PowerCLI has moved from being its own native installer to the PSGallery, the PSGallery needs to be “Trusted” before anything from it can be installed. To trust the PSGallery, entering the following command in the PowerShell session.

PS /root> Set-PSRepository -Name "PSGallery" -InstallationPolicy "Trusted"

6: Install the VMware PowerCLI module

PS /root> Find-Module "VMware.PowerCLI" | Install-Module -Scope "CurrentUser" -AllowClobber

Note: If you want powercli to be available for all users that are present in the server, you can set the “Scope” parameter to AllUsers. Also to install a different version of powercli, you can specify the “RequiredVersion” parameter and supply the version number which you want to install.

power-4.PNG

8: Verify Installed Version of PowerCLI

PS /root> Get-Module "VMware.PowerCLI" -ListAvailable | FT -Autosize
Directory: /root/.local/share/powershell/Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 10.0.0.7895300 VMware.PowerCLI

power-5.PNG

9: Check all Installed modules

PS /root> Get-Module "VMware.*" -ListAvailable | FT -Autosize

power-6.PNG

10: Import the installed modules

PS /root> Import-Module "VMware.PowerCLI"

Note; On importing the module, you will notice that the SRM module is not yet supported in PowerShell Core. Hope this will be included in future release.

power-7.PNG

11: Check connection to vCenter Server

PS /root> Connect-VIServer -Server mgmt-vc01.alex.local
Specify Credential
Please specify server credential
User: vcadmin@alex
Password for user vcadmin@alex: ***********
Name Port User
---- ---- ----
mgmt-vc01.alex.local 443 ALEX\vcadmin

12: Try running few PowerCLI Commands

PS /root> Get-VM
Name PowerState Num CPUs MemoryGB
---- ---------- -------- --------
vCD-b.alex.local PoweredOn 1 4.000
Metric-Cass-b PoweredOn 1 4.000
Metric-Cass-a PoweredOn 1 4.000
Mgmt-VCDDB PoweredOn 1 8.000
vCD-a.alex.local PoweredOn 1 4.000
Compute-VSM0 PoweredOn 4 16.000
NSX_Controller_38... PoweredOn 4 4.000
Compute-VC01 PoweredOn 2 8.000
Mgmt-vsm0 PoweredOn 4 16.000
VMware Skyline Ap... PoweredOn 2 8.000
Mgmt-VC01 PoweredOn 2 8.000
PS /root> Get-Cluster
Name HAEnabled HAFailover DrsEnabled DrsAutomationLevel
 Level
---- --------- ---------- ---------- ------------------
Mgmt-Cluster True 0 True FullyAutomated
PS /root> Get-Datacenter
Name
----
BLR-DC1

Note: If you get “InvalidCertificateAction setting ‘unset’ is not supported” error while trying to connect to vcenter server, then set the certificate checking to ignore by running below command: 

PS /root> set-PowerCLIConfiguration -InvalidCertificateAction "Ignore"

Also If you are annoyed by default message about joining CEIP, then you can disable that by running below command: 

PS /root> Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false
Perform operation?
Performing operation 'Update PowerCLI configuration.'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y
Scope ProxyPolicy DefaultVIServerMode InvalidCertificateAction DisplayDeprecationWarnings WebOperationTimeout
 Seconds
----- ----------- ------------------- ------------------------ -------------------------- -------------------
Session UseSystemProxy Multiple Ignore True 300
User Ignore
AllUsers

Finally if you want to run powercli in unrestricted mode (to use use unsigned scripts) then you can do so by running command: pwsh -ep Unrestricted

Additional Reading

PowerCLI Core Documentation

And that’s it for this post. I hope you find this post informational. Feel free to share this on social media if it is worth sharing. Be sociable 🙂