Tuesday, March 8, 2022

PowerCLI on my Ubuntu desktop

 

I think many of us one day may require to deploy and work with useful VMware PowerCLI cmdlets through our Linux-based workstations. At the first step, you need to install Microsoft PowerShell first of all. So let's do it. Remember you can login to the root access, via running the sudo -i to avoid input "sudo" in each line of command execution:

1. Keep the OS up-to-date:

# sudo apt-get update

# sudo apt-get upgrade

Keep in mind you can upgrade to the latest official version of your Ubuntu OS via:

# sudo apt-get dist-upgrade

2. You need the "Curl" as the primary prerequisite, so run this if you didn't yet:

# sudo apt-get install curl

3. Then we need to add the corresponding Microsoft Repository to get the PowerShell: 

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

In earlier versions, you may encounter some warning like deprecation of some commands like apt-key

 

# sudo curl -o /etc/apt/sources.list.d/microsoft.list https://packages.microsoft.com/config/ubuntu/21.04/prod.list

4. Execute the following commands to install and, then run the Microsoft PowerShell:

# sudo apt-get install powershell-preview

# sudo pwsh-preview  

5. Finally you got the PowerShell. Now it's time to install the latest VMware PowerCLI and even enjoy some other useful SDK of VMware products, like Horizon View:

> Install-Module -Name VMware.PowerCLI

> Install-Module -Name VMware.vSphere.Sdk

> Import-Module -Name VMware.VimAutomation.HorizonView

In most cases you need to choose your response for VMware CEIP:

> Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true

 

 

 

 

To list all available scripts about the VMware tools and solutions:

> Get-Module *vmware* -ListAvailable 

Basically, you need to connect to the vCenter server to run other required commands:

> Connect-VIServer -Server 10.10.10.100 -User administrator@vsphere.local -Password YourPass

However, you may see the invalid certificate error but you can ignore the certificate checking procedure, especially for the self-signed certificate. 


 

Although it's highly recommended to use a valid certificate in the vSphere environment and the below action is not a reliable action as the security consideration, so I think it's better to set it at least in the warning level:

> Set-PowerCLIConfiguration -InvalidCertificateAction warn

Now it's possible to use the VMware PowerCLI cmdlets through the Ubuntu Terminal, for example, you can get related information of virtual machines that are named like "DC":

> Get-VM | where-object ({$_.name -like "*DC*"}) | fl *

I hope this post can be helpful for you.



No comments:

Post a Comment

I will start a new journey soon ...