Install Powershell and PowerCLI on Ubuntu 16.04
words - read.

Install Powershell and PowerCLI on Ubuntu 16.04

VMware PowerCLI is a very handy command line interface to automate VMware vSphere environment. VMware PowerCLI leverages the Microsoft Powershell scripting language.

PowerCLI logo

Prerequisite

An Ubuntu 16.04 machine with a network access to the VMware vCenter API.

Installation of Microsoft Powershell

1- Import the Microsoft repository GPG Key.

$ curl https://packages.microsoft.com/keys/microsoft.asc | \
sudo apt-key add -

2- Add the Microsoft repository to the list of APT sources.

$ curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | \
sudo tee /etc/apt/sources.list.d/microsoft.list

3- Update the APT repositories.

$ sudo apt-get update

4- Install Microsoft Powershell.

$ sudo apt-get install powershell

Test of Microsoft Powershell

1- Start Microsoft Powershell.

$ pwsh

2- Display information about the host.

PS /home/sguyennet> Get-Host

Name : ConsoleHost Version : 6.1.0-preview.1 InstanceId : 18cc315d-06f8-4bf3-af3b-6dbf41a09641 UI : System.Management.Automation.Internal.Host. InternalHostUserInterface CurrentCulture : en-GB CurrentUICulture : en-GB PrivateData : Microsoft.PowerShell.ConsoleHost+ ConsoleColorProxy DebuggerEnabled : True IsRunspacePushed : False Runspace : System.Management.Automation.Runspaces. LocalRunspace

3- Exit the Microsoft Powershell session.

PS /home/sguyennet> exit

Installation of VMware PowerCLI

1- Start Microsoft Powershell.

$ pwsh

2- Install VMware PowerCLI.

PS /home/sguyennet> Install-Module -Name VMware.PowerCLI -Scope CurrentUser

Untrusted repository You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): Y

Test of VMware PowerCLI

1- Import the VMware PowerCLI module.

PS /home/sguyennet> Import-Module VMware.PowerCLI

2- Connect VMware PowerCLI to a VMware vCenter server.

PS /home/sguyennet> Connect-VIServer -Server vcsa.inkubate.io -force

Specify Credential Please specify server credential User: administrator@vsphere.local Password for user administrator@vsphere.local: ********** Name Port User ---- ---- ---- vcsa.inkubate.io 443 VSPHERE.LOCAL\Administrator

3- List all the virtual machines of the VMware vSphere environment.

PS /home/sguyennet> Get-VM
Name PowerState Num CPUs MemoryGB
---- ---------- -------- --------
powercli PoweredOn 1 1.000
virtual-container... PoweredOff 1 2.000
k8s-worker-0 PoweredOff 1 1.000
vra PoweredOn 4 12.000
vic PoweredOff 2 8.000
k8s-worker-2 PoweredOff 1 1.000
vra-iaas PoweredOn 1 4.000
k8s-master-0 PoweredOff 1 1.000

Comments

comments powered by Disqus