ps1Liner :: Add PowerCLi version to the $PSVersionTable variable

What is one-liner? This is just one line of code (PowerShell/PowerCLi or whatever) intended to perform particular task. It may be very or sometimes very-very long, but is still one line only!
This one-liner adds PowerCLi version to $PSVersionTable environment variable.
The technique described by Microsoft MVP Jeffery Hicks in this article.


$PSVersionTable.Add('PowerCLi Version', $(if ((Get-Module VMware.VimAutomation.Core).Version) { if ((Get-Module VMware.VimAutomation.Core).Version.ToString() -lt '6.5.2') { (Get-PowerCLIVersion).UserFriendlyVersion } else { (Get-Module VMware.VimAutomation.Core).Version } }))
  • Note, in the case of version 6.5.2 and above (in the near future), the $PSVersionTable.'PowerCLi Version' is a [version] data type and for old versions it is a simple [string].
$PSVersionTable.'PowerCLi Version'
$PSVersionTable.'PowerCLi Version' | Get-Member


  • The familiar Get-PowerCLIVersion is deprecated and give us wrong version starting from PowerCLi version 6.5.2. Let’s compare the output.
Get-Module VMware.VimAutomation.Core


How to use

  • Open your PowerShell profile script by notepad or your favorite editor.
notepad $PROFILE
  • Copy-Paste the code to your PowerShell profile script and save the changes. Reopen PowerShell console and execute $PSVersionTable.
  • Just a small requirement. For all these to work, you have to import VMware.PowerCLI module previously to run this one-liner. Add below line before one-liner.
Import-Module VMware.PowerCLI -wa SilentlyContinue


Used cmdlets

  • The core cmdlets.
  • Static methods
$PSVersionTable |gm -MemberType Method

More 1Liners

Eject CDROM drive for all VMware VM

3 thoughts on “ps1Liner :: Add PowerCLi version to the $PSVersionTable variable

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s