VMware PowerCLI is very handy and flexible automation tool allowing automation of almost all VMware features. It is based on Microsoft PowerShell. I do not have any Microsoft Windows system in my home lab but I would like to use Microsoft PowerShell. Fortunately enough, Microsoft PowerShell Core is available for Linux. Here is my latest runbook how to leverage PowerCLI in Linux management workstation leveraging Docker Application packaging.
Install Docker in your Linux Workstation
This is out of scope of this runbook.
Pull official and verified VMware PowerCLI
sudo docker pull vmware/powercli:latest
Pull official and verified Microsoft Powershell
sudo docker pull mcr.microsoft.com/powershell:latest
List container images
sudo docker image ls
How to run container?
Now you can run any of two above powershell/powercli containers interactively (-i) and in allocated pseudo-TTY (-t).
The -v option in Docker is used to mount volumes, allowing data to persist or be shared between the host and the container. We can map our Linux host directory /home/dpasek/scripts in to container directory /tmp/scripts This allow us to store our scripts permanently even we exit and remove the PowerShell container.
sudo docker run -it CONTAINER-NAME
VMware PowerCLI container
Using VMware PowerCLI container is easier because it contains PowerShell with PowerCLI prepared by VMware
This command will run VMware PowerCLI and you have everything ready to go.
sudo docker run -it -v /home/dpasek/scripts:/root/scripts vmware/powerclicore
The -v option in Docker is used to mount volumes, allowing data to
persist or be shared between the host and the container. We map our
Linux host directory /home/dpasek/scripts in to container directory /tmp/scripts This allow us to store our scripts permanently even we exit or even remove the PowerShell container.
To work with PowerCLI, the following commands are necessary to initialize PowerCLI configuration.
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true
Set-PowerCLIConfiguration -InvalidCertificateAction:ignore
... and now you can connect to vCenter and list VMs
Microsoft PowerShell container
If you want use Microsoft PowerShell container, you can, but you have to install PowerCLI manualy.
Following command will run Microsoft PowerShell
sudo docker run -it -v /home/dpasek/scripts:/root/scripts mcr.microsoft.com/powershell
Inside Microsoft PowerShell container, you must install PowerCLI manualy
Install-Module -Name VMware.PowerCLI -Scope CurrentUser -Force
You must allow untrusted certificates and enable (or disable) participation in VMware CEIP.
And now you can connect to vCenter and list VMs
No comments:
Post a Comment