Get Powershell version | on a single | multiple remote computers using a simple Powershell code to get the version.
There are 3 ways you can check the PowerShell version that is installed on your computer, let’s pull the version information using these 3 methods.
1. $PSVersinTable
This is a default variable gives you the PowerShell version information and Build version of your machine when you pass this variable in PowerShell window you get below details.
$PSversionTable
OutPut:
Name Value
—- —–
PSVersion 5.1.17763.771
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
BuildVersion 10.0.17763.771
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1.
When you want to retrieve only version information then use the below variable property.
$PSversionTable.PSVersion
output:
Major Minor Build Revision.
—– —– —– ——–
5 1 17763 771
2. Get-Host
This is a Powershell cmdlet, and it also gives the Powershell version details.
3. Powershell version using the Windows Registry:
Open the registry edit, goto Run and type in Regedit, and navigate to the path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine
And see the key PowerShellVersion and value data.
Getting the Powershell version on a single remote machine
Using Registry
$version = { [version](Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name ‘PowerShellVersion’).PowerShellVersion } Invoke-Command -ComputerName Machine01 -ScriptBlock $version -Credential $cred
output:
Major Minor Build Revision PSComputerName
—– —– —– ——– ————–
5 1 17763 1 Machine01
Using $PSVersionTable
Invoke-Command -ComputerName DESKTOP-MYVDI10 -ScriptBlock {$PSVersionTable.PSVersion}
The above command gets the PowerShell version on the remote machine DESKTOP-MYVDI10.
Getting the Powershell version on more remote machines
Let’s check it Multiple Remote Machines
we need to create one more file for storing the all the servers or multiple machines, I named it Allserver.txt storing it in my local machine c:\temp\Allserver.tx
#create a text file which has all the list of servers and located in c:\temp\Allserver.txt $serverlist = Get-Content -Path "c:\temp\Allserver.txt" foreach($server in $serverlist) { Invoke-Command -ComputerName $server -ScriptBlock {$PSversionTable.PSVersion} }
Thank you for reading this article, if you have any questions please let us know.
Thank you for visiting my site, for any scripts in these articles you are testing please make sure you have tested this script in our lower environment before you run in production.
Leave a Reply Cancel reply