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.
Add yourself to User Group docker
sudo usermod -aG docker $USER
Note: you must logout and login back to be able to run docker.
Pull official and verified VMware PowerCLI
docker pull vmware/powercli:latest
Pull official and verified Microsoft Powershell
docker pull mcr.microsoft.com/powershell:latest
List container images
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).
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.
The -v option in Docker is used to mount volumes, allowing data to persist or be shared between the host and the container.
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true -Confirm:$false
Set-PowerCLIConfiguration -InvalidCertificateAction:ignore -Confirm:$false
... and now you can connect to vCenter and list VMs
... if we have PowerShell script prepared, we can run it directly from the host system. Following example will run script /tmp/scripts/get-vms.ps1
docker run -it \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
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, display vCenter Instance UUID, list ESXi hosts, and list VMs
(Get-View ServiceInstance).Content.About.InstanceUuid
Get-VMhost
No comments:
Post a Comment