{"id":1197,"date":"2018-03-04T15:55:41","date_gmt":"2018-03-04T20:55:41","guid":{"rendered":"https:\/\/ithinkvirtual.com\/?p=1197"},"modified":"2018-03-31T07:27:42","modified_gmt":"2018-03-31T11:27:42","slug":"install-powershell-and-vmware-powercli-on-ubuntu","status":"publish","type":"post","link":"https:\/\/ithinkvirtual.com\/2018\/03\/04\/install-powershell-and-vmware-powercli-on-ubuntu\/","title":{"rendered":"Install PowerShell and VMware PowerCLI on Ubuntu"},"content":{"rendered":"

Just a few days ago, PowerShell Core v6.0<\/a> was released for Windows, Linux, and macOS systems. \u00a0Alongside this release came the release of VMware PowerCLI 10.0.0.78953<\/a> which is VMware’s own “PowerShell-like” utility. \u00a0<\/p>\r\n

In my previous posts (here<\/a> and here<\/a>), I covered how to install those on to a macOS 10.13.x “High Sierra” system and a CentOS 7 system.\u00a0 In this post, I am going to show how to install both on to an Ubuntu 17.10 system as this is another common distro which I also use in my environments.\u00a0 Let’s get to it!<\/p>\r\n

Note:\u00a0If you’re interested in installing this on other Linux distros, please consult the following link<\/a>.<\/strong><\/em><\/span><\/p>\r\n

There is a prerequisite needed before PowerShell can be installed on Ubuntu and that is to install “curl<\/em>” and then add the\u00a0PowerShell Core repository (recommended) to your system.<\/p>\r\n

To install curl, enter the following.<\/p>\r\n

sudo apt-get install -y curl<\/pre>\r\n

\"\"<\/a> \"\"<\/a>To add the PowerShell Core repository to Ubuntu, run the following command.\u00a0 Enter your password if prompted<\/p>\r\n

curl https:\/\/packages.microsoft.com\/keys\/microsoft.asc | sudo apt-key add -<\/pre>\r\n

\"\"<\/a> \"\"<\/a>To register the repository, enter the following command.\u00a0 Again, enter your password if prompted.<\/p>\r\n

curl https:\/\/packages.microsoft.com\/config\/ubuntu\/17.04\/prod.list | sudo tee \/etc\/apt\/sources.list.d\/microsoft.list<\/pre>\r\n

\"\"<\/a> \"\"<\/a>Great! \u00a0With the prerequisites complete, it’s time to install PowerShell Core 6.0.1. \u00a0Run the following command to do so and enter your password when prompted.<\/p>\r\n

sudo apt-get install -y powershell<\/pre>\r\n

\"\"<\/a> \"\"<\/a>Awesome! \u00a0Now, to launch a PowerShell session in CentOS, enter the following.<\/p>\r\n

pwsh<\/pre>\r\n

\"\"<\/a>Within a PowerShell session, you can check the version of PowerShell by running the following.<\/p>\r\n

$PSVersionTable.PSVersion<\/pre>\r\n

\"\"<\/a>As new versions of\u00a0PowerShell are released, simply update by running the following command.<\/p>\r\n

sudo apt-get upgrade -y powershell<\/pre>\r\n

While leveraging the PowerShell Core repository is the recommended installation method, there are alternate methods as well. \u00a0For more information on that along with uninstallation commands, please see the following link<\/a>.<\/p>\r\n

Congratulations! \u00a0You’ve successfully installed PowerShell Core 6.0.1 onto Ubuntu! \u00a0Next comes the fun stuff for us VMware enthusiasts, installing VMware PowerCLI from the “PSGallery”. \u00a0Let’s continue!<\/p>\r\n

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. \u00a0To trust the PSGallery, entering the following command in the PowerShell session.<\/p>\r\n

Note: This is optional and if it is skipped, you will be prompted to trust the gallery when entering the PowerCLI module install command<\/em><\/strong><\/span><\/p>\r\n

Set-PSRepository -Name \"PSGallery\" -InstallationPolicy \"Trusted\"<\/pre>\r\n

\"\"<\/a>Next, run the following command to install the VMware.PowerCLI module. \u00a0This will find and install the latest version of the module available in the PSGallery<\/p>\r\n

Find-Module \"VMware.PowerCLI\" | Install-Module -Scope \"CurrentUser\" -AllowClobber<\/pre>\r\n

Note: Alternatively, you could set the “-Scope” parameter to “AllUsers” and if you wanted to install a different version you could use the “-RequiredVersion” parameter and specify the version number.<\/em><\/span><\/strong><\/p>\r\n

\"\"<\/a> \"\"<\/a>Once this finishes, we can check to make sure the module is installed by running the following command.<\/p>\r\n

Get-Module \"VMware.PowerCLI\" -ListAvailable | FT -Autosize<\/pre>\r\n

\"\"<\/a>And if you’d like to see all of the VMware installed modules, run the following.<\/p>\r\n

Get-Module \"VMware.*\" -ListAvailable | FT -Autosize<\/pre>\r\n

\"\"<\/a>As new versions of VMware.PowerCLI are released, you can run the following command to update it.<\/p>\r\n

Update-Module \"VMware.PowerCLI\"<\/pre>\r\n

With VMware.PowerCLI now installed, you can connect to your vCenter Server or ESXi host and begin using its cmdlets to obtain information or automate tasks!<\/p>\r\n

I went ahead and ran the following to ensure the module was imported. \u00a0<\/p>\r\n

Import-Module \"VMware.PowerCLI\"<\/pre>\r\n

\"\"<\/a>I noticed one caveat, the SRM module does not seem to be supported in PowerShell Core, so I hope that gets resolved soon.<\/p>\r\n

\"\"<\/a><\/p>\r\n

Let’s test connecting to vCenter server…<\/p>\r\n

Connect-VIServer -Server \"<Server_Name><\/em>\"<\/pre>\r\n

I also noticed an error when running the above command stating that the “InvalidCertificateAction” setting was “Unset” and not supported.<\/p>\r\n

\"\"<\/a>To bypass this, enter the following command and then enter “Y” when prompted. \u00a0This will set the parameter for the current user.<\/p>\r\n

Set-PowerCLIConfiguration -InvalidCertificateAction \"Ignore\"<\/pre>\r\n

\"\"<\/a>Note: Alternatively, you can also use the “-Scope” parameter and enter “Session”, “User”, or “AllUsers” to apply the setting to those options respectively.<\/strong><\/em><\/span><\/p>\r\n

Now, if we try to connect to vCenter again, we should be successful.<\/p>\r\n

\"\"<\/a>Well, that about does it! \u00a0I hope that you have found this post useful and I thank you for stopping by and reading my content.\u00a0 Until next time!<\/p>\r\n

-virtualex-<\/p>\r\n

Pingbacks:\u00a0<\/p>\r\n