Install PowerShell and PowerCLI on CentOS 7 Linux

I never thought I’d be doing this, but here’s how to install PowerShell (yes, that Powershell) on our beloved GNU/Linux. I need it because I want to automate some VMware tasks and PowerCLI is available for Linux through powershell.

curl https://packages.microsoft.com/config/rhel/7/prod.repo -o- | sudo tee /etc/yum.repos.d/microsoft.repo
sudo yum install -y powershell

Now powershell is installed, on GNU/Linux! Let’s contain our horror and keep moving forward. Open powershell and install the PowerCLI components.

pwsh
Set-PSRepository -Name "PSGallery" -InstallationPolicy "Trusted"
Find-Module "VMware.PowerCLI" | Install-Module -Scope "CurrentUser" -AllowClobber
Import-Module "VMware.PowerCLI"

List what is available now with

Get-Module "VMware.*" -ListAvailable | FT -Autosize

And most VMware instances I’ve seen don’t have pristine ssl certs, so you might want to run:

Set-PowerCLIConfiguration -InvalidCertificateAction:Ignore

Maintenance tasks include updating the PowerCLI modules.

Update-Module "VMware.PowerCLI"

References

Weblinks

  1. Shamelessly ripped from Install PowerShell and VMware PowerCLI on CentOS | iThinkVirtual
  2. Zsoldier’s Tech Blog: PowerCLI: The SSL connection could not be established, see inner exception.

Linux get vmware tools version

$( { find /sbin /usr/sbin /usr/local/bin /bin /usr/bin -name 'vmtoolsd'; echo /bin/true; } | head -n1 ) -v

Regardless of deployment method (RHEL6 by inserting the virtual disc, or RHEL7 rpm for open-vm-tools), this should work for you.

Update on 2019-08-20

And from PowerCLI:

get-vm | % { get-view $_.id } | select Name, @{ Name="ToolsVersion"; Expression={$_.config.tools.toolsVersion}},@{ Name="ToolStatus"; Expression={$_.Guest.ToolsVersionStatus}}

References

  1. Original research
  2. Powercli – How to get Vmware tools version – Virtual Me