The $PSVersionTable automatic variable in PowerShell checks the PowerShell version and gets the PSVersion.
$PSVersionTable
is an automatic variable in PowerShell is a read-only hash table that returns PowerShell Version (PSVersion) information and PSEdition information either Core or Desktop.
In PowerShell, it has different ways to get the PowerShell version using Get-Host, $Host, and $PSVersionTable you can get the PowerShell version.
Check PowerShell Version using PSVersionTable
Use $PSVersionTable
automatic variable in PowerShell to get running PowerShell version on your local computer.
Run the below command to get the PowerShell version.
$PSVersionTable.PSVersion
The above PSVersionTable variable retrieves PSVersion as below
PS C:\> $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 1 18362 1474
PS C:\>
PSVersionTable gets Major version, minor version, Build, and Revision information about PowerShell.
Check PowerShell Version remotely using PSVersionTable
Use the $PSVersionTable automatic variable to check PowerShell version on a remote computer, use the below command to get PSVersion
Invoke-Command -ComputerName incorp-eu-101 -ScriptBlock {$PSVersionTable.PSVersion}
In the above PowerShell script, it uses Invoke-Command
to run command on the remote computers specified by computer name and using PSVersionTable.PSVersion gets the PowerShell version on a remote computer.
Get PowerShell Version using Get-Host
Use the Get-Host cmdlet in PowerShell to get the host program that is hosting Windows PowerShell and find the PowerShell version on a local computer and remote computer.
When you run the Get-Host cmdlet in the PowerShell console, it returns host information which contains PowerShell version, Current Culture, CurrentUICulture, etc…
Get-Host
The Get-Host command gets the PowerShell version and other information below
If you try to use the Get-Host cmdlet to get the remote computer PowerShell version, it may not get the correct version details, hence avoid using it and use the $PSVersionTable variable to get the PowerShell version.
Cool Tip: How to get a list of PowerShell modules!
Get PowerShell Version using $Host
Use the $Host automatic variable for the PowerShell version check, use the below command
$Host
The above $Host
automatic variable in PowerShell finds the same information about PowerShell as Get-Host
cmdlet does.
The output of the above command as below
PS C:\> $Host
Name : ConsoleHost
Version : 5.1.18362.1474
InstanceId : 257ef135-307f-4a09-9ca7-d9543c96129b
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-IN
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
Cool Tip: Do you know which are approved verbs in PowerShell?
Conclusion
I hope the above article on how to check the PowerShell version on a local computer and PSVersion on a remote computer is helpful to you.
As an administrator, we always need to make sure the system has an updated PowerShell version on each of the systems in the domain.
$PSVersionTable
automatic variable in PowerShell is the best way to get the PowerShell version of the local computer as well using the Invoke-Command cmdlet you can get the PowerShell version remotely from other computers in the domain.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.