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
1 |
<em><span style="color: #000000;">[root@mgmt-grafana ~]# curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo</span></em> |
2: Install PowerShell
1 |
<em><span style="color: #000000;">[root@mgmt-grafana ~]# yum install powershell -y</span></em> |
3: Launch PowerShell session
1 2 3 4 5 6 |
<em><span style="color: #000000;">[root@mgmt-grafana ~]# pwsh</span></em> <em><span style="color: #000000;">PowerShell v6.0.2</span></em> <em><span style="color: #000000;">Copyright (c) Microsoft Corporation. All rights reserved.</span></em> <em><span style="color: #000000;">https://aka.ms/pscore6-docs</span></em> <em><span style="color: #000000;">Type 'help' to get help.</span></em> <em><span style="color: #000000;">PS /root></span></em> |
4: Verify PowerShell Version
1 2 3 4 5 6 |
<em><span style="color: #000000;">PS /root> $PSVersionTable.PSVersion</span></em> <em><span style="color: #000000;">Major Minor Patch PreReleas BuildLabel</span></em> <em><span style="color: #000000;"> eLabel</span></em> <em><span style="color: #000000;">----- ----- ----- --------- ----------</span></em> <em><span style="color: #000000;">6 0 2</span></em> <em><span style="color: #000000;">PS /root></span></em> |
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.
1 |
<em><span style="color: #000000;">PS /root> Set-PSRepository -Name "PSGallery" -InstallationPolicy "Trusted"</span></em> |
6: Install the VMware PowerCLI module
1 |
<em><span style="color: #000000;">PS /root> Find-Module "VMware.PowerCLI" | Install-Module -Scope "CurrentUser" -AllowClobber</span></em> |
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.
8: Verify Installed Version of PowerCLI
1 2 3 4 5 |
<em><span style="color: #000000;">PS /root> Get-Module "VMware.PowerCLI" -ListAvailable | FT -Autosize</span></em> <em><span style="color: #000000;">Directory: /root/.local/share/powershell/Modules</span></em> <em><span style="color: #000000;">ModuleType Version Name ExportedCommands</span></em> <em><span style="color: #000000;">---------- ------- ---- ----------------</span></em> <em><span style="color: #000000;">Manifest 10.0.0.7895300 VMware.PowerCLI</span></em> |
9: Check all Installed modules
1 |
<em><span style="color: #000000;">PS /root> Get-Module "VMware.*" -ListAvailable | FT -Autosize</span></em> |
10: Import the installed modules
1 |
<em><span style="color: #000000;">PS /root> Import-Module "VMware.PowerCLI"</span></em> |
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.
11: Check connection to vCenter Server
1 2 3 4 5 6 7 8 |
<em><span style="color: #000000;">PS /root> Connect-VIServer -Server mgmt-vc01.alex.local</span></em> <em><span style="color: #000000;">Specify Credential</span></em> <em><span style="color: #000000;">Please specify server credential</span></em> <em><span style="color: #000000;">User: vcadmin@alex</span></em> <em><span style="color: #000000;">Password for user vcadmin@alex: ***********</span></em> <em><span style="color: #000000;">Name Port User</span></em> <em><span style="color: #000000;">---- ---- ----</span></em> <em><span style="color: #000000;">mgmt-vc01.alex.local 443 ALEXvcadmin</span></em> |
12: Try running few PowerCLI Commands
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<span style="color: #ff0000;"><em>PS /root> Get-VM</em></span> <em><span style="color: #000000;">Name PowerState Num CPUs MemoryGB</span></em> <em><span style="color: #000000;">---- ---------- -------- --------</span></em> <em><span style="color: #000000;">vCD-b.alex.local PoweredOn 1 4.000</span></em> <em><span style="color: #000000;">Metric-Cass-b PoweredOn 1 4.000</span></em> <em><span style="color: #000000;">Metric-Cass-a PoweredOn 1 4.000</span></em> <em><span style="color: #000000;">Mgmt-VCDDB PoweredOn 1 8.000</span></em> <em><span style="color: #000000;">vCD-a.alex.local PoweredOn 1 4.000</span></em> <em><span style="color: #000000;">Compute-VSM0 PoweredOn 4 16.000</span></em> <em><span style="color: #000000;">NSX_Controller_38... PoweredOn 4 4.000</span></em> <em><span style="color: #000000;">Compute-VC01 PoweredOn 2 8.000</span></em> <em><span style="color: #000000;">Mgmt-vsm0 PoweredOn 4 16.000</span></em> <em><span style="color: #000000;">VMware Skyline Ap... PoweredOn 2 8.000</span></em> <em><span style="color: #000000;">Mgmt-VC01 PoweredOn 2 8.000</span></em> <span style="color: #ff0000;"><em>PS /root> Get-Cluster</em></span> <em><span style="color: #000000;">Name HAEnabled HAFailover DrsEnabled DrsAutomationLevel</span></em> <em><span style="color: #000000;"> Level</span></em> <em><span style="color: #000000;">---- --------- ---------- ---------- ------------------</span></em> <em><span style="color: #000000;">Mgmt-Cluster True 0 True FullyAutomated</span></em> <span style="color: #ff0000;"><em>PS /root> Get-Datacenter</em></span> <em><span style="color: #000000;">Name</span></em> <em><span style="color: #000000;">----</span></em> <em><span style="color: #000000;">BLR-DC1</span></em> |
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:
1 |
<span style="color: #000000;"><em>PS /root> set-PowerCLIConfiguration -InvalidCertificateAction "Ignore"</em></span> |
Also If you are annoyed by default message about joining CEIP, then you can disable that by running below command:
1 2 3 4 5 6 7 8 9 10 |
<span style="color: #000000;"><em>PS /root> Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false</em></span> <span style="color: #000000;"><em>Perform operation?</em></span> <span style="color: #000000;"><em>Performing operation 'Update PowerCLI configuration.'?</em></span> <span style="color: #000000;"><em>[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y</em></span> <span style="color: #000000;"><em>Scope ProxyPolicy DefaultVIServerMode InvalidCertificateAction DisplayDeprecationWarnings WebOperationTimeout</em></span> <span style="color: #000000;"><em> Seconds</em></span> <span style="color: #000000;"><em>----- ----------- ------------------- ------------------------ -------------------------- -------------------</em></span> <span style="color: #000000;"><em>Session UseSystemProxy Multiple Ignore True 300</em></span> <span style="color: #000000;"><em>User Ignore</em></span> <span style="color: #000000;"><em>AllUsers</em></span> |
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
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 🙂