VMware released PowerCLI Core for Linux and Mac that allows users to run cmdlets, which were possible to run only on Windows earlier. This post captures details on how to install PowerCLI Core on CentOS 7.

Steps Involved
  1. Install Microsoft .NET Core
  2. Install PowerShell
  3. Compile curl from source
  4. Install PowerCLI Core

Install Microsoft .Net Core

.NET Core can be installed by following the guide at https://www.microsoft.com/net/core#linuxcentos

sudo yum install libunwind libicu
curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=835019
sudo mkdir -p /opt/dotnet
sudo tar zxf dotnet.tar.gz -C /opt/dotnet
sudo ln -s /opt/dotnet/dotnet /usr/local/bin
PowerShell

Install PowerShell CLI following instructions at https://github.com/PowerShell/PowerShell/blob/master/docs/installation/linux.md#centos-7

sudo yum -y install https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.14/powershell-6.0.0_alpha.14-1.el7.centos.x86_64.rpm
PowerCLI Core

Use the commands below to install PowerCLI core

curl -sSL -o PowerCLI_Core.zip https://download3.vmware.com/software/vmw-tools/powerclicore/PowerCLI_Core.zip
yum -y install unzip
mkdir -p ~/.local/share/powershell/Modules
unzip PowerCLI_Core.zip && unzip 'PowerCLI.*.zip' -d ~/.local/share/powershell/Modules
Test PowerCLI

On the command prompt, enter the commands below.

powershell
Get-Module -ListAvailable PowerCLI* | Import-Module

Connect to vcenter, using Connect-VIServer command and replacing text highlighted below appropriately.

Connect-VIServer -Server vcenter.example.com -User administrator@vsphere.local -Password VCENTERADMINPASSWORD

You will see an error similar to one below.

Error
Connect-VIServer : 1/5/17 12:52:26 AM Connect-VIServer The libcurl library in use (7.29.0) and its SSL backend (“NSS/3.21 Basic ECC”) do not support custom handling of certificates. A libcurl built with OpenSSL is required.
At line:1 char:1
+ Connect-VIServer -Server vcenter.example.com -User administ …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-VIServer], ViError
+ FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_Exception,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer

This error is because CentOS 7 default curl is built with NSS/3.21, while, .NET needs libcurl compiled with OpenSSL. In order to resolve the issue, curl built in with CentOS 7 can’t be used and must be replaced.

curl --version
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.21 Basic ECC zlib/1.2.7 libidn/1.28 libssh2/1.4.3

Follow the instructions below to compile curl from source. curl 7.52.1 was the latest at the time this post was written. Please browse to curl homepage

yum -y groupinstall “Development Tools”
curl -sSL -o curl-7.52.1.tar.gz https://curl.haxx.se/download/curl-7.52.1.tar.gz
tar -zxvf curl-7.52.1.tar.gz
cd curl-7.52.1
./configure
make
make install

Verify that the curl version is built with OpenSSL

/usr/local/bin/curl --version
curl 7.52.1 (x86_64-pc-linux-gnu) libcurl/7.52.1 OpenSSL/1.0.1e

zlib/1.2.7

Modify LD_CONFIG_PATH

LD_LIBRARY_PATH is an environment variable that can be used to provide list of directories, when a program needs to search for shared libraries. The libcurl library was installed in /usr/local/lib, when curl was compiled and installed from source.

Follow the procedure below to set the path appropriately.

cd /etc/ld.so.conf.d/

Create a file called libcurl.conf and enter

/usr/local/lib

in it.

Run “ldconfig” to update the shared library cache.

ldconfig
Use PowerCLI to connect to vCenter
powershell
Get-Module -ListAvailable PowerCLI* | Import-Module

Connect to vcenter, using Connect-VIServer command and replacing text highlighted below appropriately.

Connect-VIServer -Server vcenter.example.com -User administrator@vsphere.local -Password VCENTERADMINPASSWORD

If you get an invalid server certificate warning similar to one below, set use the Set-PowerCLIConfiguration so that Invalid Certification warnings are ignored.

WARNING: Invalid server certificate. Use Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to Prompt if you’d like to connect once or to add a permanent exception for this server.

Commands:

powershell
Get-Module -ListAvailable PowerCLI* | Import-Module
Set-PowerCLIConfiguration -InvalidCertificateAction ignore -confirm:$false

Verify the changes by running the command below

Get-PowerCLIConfiguration                                                                                                                                                                                                           

Scope    ProxyPolicy     DefaultVIServerMode InvalidCertificateAction  DisplayDeprecationWarnings WebOperationTimeout
                                                                                                  Seconds            
-----    -----------     ------------------- ------------------------  -------------------------- -------------------
Session  UseSystemProxy  Multiple            Ignore                    True                       300                
User                                         Ignore                                                                  
AllUsers                                                  

Enjoy using PowerCLI Core on CentOS 7.

print