Skip to content

Getting Started with PowerCLI for Linux (PowerCLI Core)

powerclicoreBased on Microsoft PowerShell Core which enables users to use PowerShell on Linux, Mac and Docker, VMware has started to make PowerCLI compatible with the new PowerShell. This allows to run scripts that were previously only available for Windows on Linux or Mac based systems.

In this post I am going to give a quick startup guide to the installation and configuration of PowerCLI Core.

This guide is based on an Ubuntu 14.04 LTS Linux box which I am using to manage my vSphere Lab.

PowerCLI Core Installation

  1. Install required packages.
    # apt-get install ca-certificates curl libunwind8 libicu52 unzip wget libcurl4-openssl-dev
  2. Download the latest version of PowerShell. You can get the latest version for your OS here.

    # wget
  3. Install the PowerShell package. The apt-get install -f command will install missing dependencies.
    # dpkg -i powershell_6.0.0-alpha.11-1ubuntu1.14.04.1_amd64.deb
    # apt-get install -f
  4. Create the PowerShell module directory.
    # mkdir -p ~/.local/share/powershell/Modules
  5. Download PowerCLI Core and extract the modules to the default module directory.
    # wget
    # unzip && unzip 'PowerCLI.*.zip' -d ~/.local/share/powershell/Modules
  6. You should now be able to start PowerShell and load VMware PowerCLI Core modules.
    # powershell
    PS /> Get-Module -ListAvailable PowerCLI* | Import-Module
  7. Connect to a vCenter Server
    PS /> Connect-VIServer -Server vcsa.virten.lab -User administrator@vsphere.local -Password vmware123

Fix Self-Signed Certificates Issue

When the vCenter Server uses an untrusted self-signed certificate, you will see the following warning and the connection will fail:

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.
Connect-VIServer : 23.10.16 19:53:11 Connect-VIServer An error occurred while sending the request.

Starting with vSphere 6.0 you can easily download root certificates from the vCenter Server. Include the certificates to /etc/ca-certificates.conf and do a dpkg-reconfigure ca-certificates.

# wget https://vcsa.virten.lab/certs/download --no-check-certificate -O
# unzip
# mkdir /usr/share/ca-certificates/extra
# cp certs/*.0 /usr/share/ca-certificates/extra/vcsa.virten.lab.crt
# echo "extra/vcsa.virten.lab.crt" >> /etc/ca-certificates.conf
# dpkg-reconfigure ca-certificates

If this does not resolve the issue, you can set PowerShell to ignore certificate proglems.

PS /> Set-PowerCLIConfiguration -InvalidCertificateAction Ignore

Load PowerCLI Modules on PowerShell Startup

A profile script makes it possible to load PowerCLI Modules on startup. I had a small issue with the configuration because Linux is case-sensitive while Microsofts PowerShell isn't. The default profile script is stored in the $profile variable:

PS /> $profile

However, the directory that comes with the installer is: /root/.config/PowerShell/
As a workaround, I've created a symlink:

# ln -s /root/.config/PowerShell/ /root/.config/powershell

Add the command to import modules to the profile script.

# echo "Get-Module -ListAvailable PowerCLI* | Import-Module" >> /root/.config/PowerShell/Microsoft.PowerShell_profile.ps1

PowerCLI commands are now automatically loaded when you start PowerShell.

# powershell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

Loading personal and system profiles took 851ms.
PS />

10 thoughts on “Getting Started with PowerCLI for Linux (PowerCLI Core)”

  1. Pingback: Hot VMware Topics - October

  2. Michael van Blijdesteijn

    Is there an equivalent to
    # wget https://vcsa.virten.lab/certs/download --no-check-certificate -O
    # unzip
    # mkdir /usr/share/ca-certificates/extra
    # cp certs/*.0 /usr/share/ca-certificates/extra/vcsa.virten.lab.crt
    # echo "extra/vcsa.virten.lab.crt" >> /etc/ca-certificates.conf
    # dpkg-reconfigure ca-certificates

    for the VCSA 6.5 on Photon OS?


    Mike van

    1. Sure, there are only minor changes to the format in vSphere 6.5:
      Downloading is now "" instead of "download" and the bundle contains subfolders:

      # wget https://vcsa.virten.lab/certs/ --no-check-certificate
      # unzip
      # mkdir /usr/share/ca-certificates/extra
      # cp certs/win/*.crt /usr/share/ca-certificates/extra/vcsa.virten.lab.crt
      # echo "extra/vcsa.virten.lab.crt" >> /etc/ca-certificates.conf
      # dpkg-reconfigure ca-certificates

      1. Michael van Blijdesteijn

        Thanks for the quick response.
        I can do everything except the dpkg-reconfigure.
        It doesn't seem to be installed, apt-get is also not installed. how do I get dpkg-reconfigure so that I can complete the steps.

        Thanks again

        mike van

  3. Thanks for nice tutorial
    I try installing powercli on ubuntu 16.04.2 LTS with these instructions but I'm stuck at step 6:

    Get-Module -ListAvailable PowerCLI* | Import-Module

    Import-Module : The system cannot find the file specified.
    (Exception from HRESULT: 0x80070002)

    here is the output of "Get-Module -ListAvailable" :

    PS /root> Get-Module -ListAvailable

    Directory: /root/.local/share/powershell/Modules

    ModuleType Version Name ExportedCommands
    ---------- ------- ---- ----------------
    Binary PowerCLI.Cis
    Binary 1.21 PowerCLI.Vds
    Binary 1.21 PowerCLI.ViCore HookGetViewAutoCompleter

    Directory: /opt/microsoft/powershell/6.0.0-beta.3/Modules

    ModuleType Version Name ExportedCommands
    ---------- ------- ---- ----------------
    Manifest Microsoft.PowerShell.Archive {Compress-Archive, Expand-Archive}
    Manifest Microsoft.PowerShell.Host {Start-Transcript, Stop-Transcript}
    Manifest Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-ItemProperty, Join-Path...}
    Manifest Microsoft.PowerShell.Security {Get-Credential, Get-ExecutionPolicy, Set-ExecutionPolicy, ConvertFrom-SecureString...}
    Manifest Microsoft.PowerShell.Utility {Format-List, Format-Custom, Format-Table, Format-Wide...}
    Script PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}
    Script 3.3.9 Pester {Describe, Context, It, Should...}
    Binary PowerCLI.Cis
    Binary 1.21 PowerCLI.Vds
    Binary 1.21 PowerCLI.ViCore HookGetViewAutoCompleter
    Script PowerShellGet {Install-Module, Find-Module, Save-Module, Update-Module...}
    Script 0.0 PSDesiredStateConfiguration {ThrowError, Get-PSMetaConfigDocumentInstVersionInfo, New-DscChecksum, ValidateNodeResourceSource...}
    Script 1.2 PSReadLine {Get-PSReadlineKeyHandler, Set-PSReadlineKeyHandler, Remove-PSReadlineKeyHandler, Get-PSReadlineOption...}

    1. Alexey Polovinkin

      I faced with same problem. It is a bug of a powercli. WA - use alpha version instead beta (18th, for example).

Leave a Reply

Your email address will not be published. Required fields are marked *