how to know what version of powershell i have

In PowerShell, there are a zillion ways to do the same thing (or close to it). In this web log postal service, you'll learn every way check PowerShell version that you have on local and remote computers. Nosotros'll comprehend the bad ways and my recommended way.

At that place are websites that show diverse ways to check Powershell version. Only none that compiled a comprehensive list of all them. I decided to alter that.

All these ways should work in both Windows PowerShell and PowerShell Cadre. These methods should also work in Windows PowerShell versions 1.0 all the fashion upwards to PowerShell 7.

The ways you can observe out a version of PowerShell you're running are:

  1. The (Get-Host).Version property
  2. The $host.Version property
  3. The registry (Windows PowerShell only)
  4. The $PSVersionTable.PSVersion property

Let's intermission downward all the ways to find the version of PowerShell from least to well-nigh recommended way.

Become-Host

PowerShell has a concept known every bit hosts. A host is a programme that is hosting the PowerShell engine. It is not the PowerShell engine itself.The PowerShell console or a code editor with an integrated terminal are PowerShell hosts.

A host can take a version that is completely independent of PowerShell itself. This tin can exist deceiving to many newcomers. Let me prove you why.

If you run (Become-Host).Version, you'll run across that it returns a version number that looks like it could be the PowerShell engine version. Looks tin can exist deceiving.

Below I've ran Get-Host on Windows PowerShell 5.i and you lot tin can see it comes back with 5.i.17134.858. This looks like a legitimate version.

            PS51> (Get-Host).Version Major  Small  Build  Revision -----  -----  -----  -------- v      one      17134  858          

Nonetheless, sometimes when you run Become-Host in an integrated final, the version is not the same. Although usually the host volition represent the aforementioned version of the engine, it doesn't necessary ever do that.

Check Powershell Version via Get-Host on Remote Computers

Even though Get-Host seems to render the same version when run on a local figurer, it never will on remote computers.

For example, let's run Get-Host on a remote Windows Server 2016 server via Invoke-Command and see what happens.

            PS51> Invoke-Command -ComputerName 10.0.0.5 -ScriptBlock {Get-Host} -Credential $cred  Major  Small  Build  Revision PSComputerName -----  -----  -----  -------- -------------- i      0      0      0        10.0.0.5          

The last fourth dimension I checked, it's not possible to run PowerShell v1 on Windows Server 2016.

Relying on Become-Host is just a bad idea all around.

Cheque Powershell Version $host.Version command

Referencing $host.Version is some other way to check Powershell version. The $host variable is an automatic variable that returns the aforementioned output equally Go-Host.

Referencing $host.Version
Referencing $host.Version

There's zilch special about this method. It'due south simply the same as running Become-Host.

$host.Version on Remote Computers

Yous will see the same behavior via PowerShell Remoting with $host.Version as you lot will running Get-Host.

            PS51> Invoke-Command -ComputerName 10.0.0.5 -ScriptBlock {$host.Version} -Credential $cred  Major  Small-scale  Build  Revision PSComputerName -----  -----  -----  -------- -------------- 1      0      0      0        10.0.0.5          

Danger, Will Robinson!

Registry

If you don't want to open upward PowerShell itself, y'all tin can also cheque the registry. The version of PowerShell is tucked away nether a value in the registry fundamental path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine. This registry key has a value called PowerShellVersion that you can reference by using Get-ItemProperty.

            PS51> (Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name 'PowerShellVersion').PowerShellVersion 5.1.17134.1          

Y'all can encounter that this version is similar but doesn't include the revision like the other options exercise.

            PS51> [version](Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Proper name 'PowerShellVersion').PowerShellVersion  Major  Minor  Build  Revision -----  -----  -----  -------- five      one      17134  1          

Using Other Tools

Using the registry also ways y'all don't need to use PowerShell at all to find the version. You can run commands from the command prompt or some other tool that can read the registry.

            CMD> reg query HKLM\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine /v PowerShellVersion  HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\iii\PowerShellEngine     PowerShellVersion    REG_SZ    v.1.17134.1          

Registry on Remote Computers

The registry is static and the values won't modify locally or remotely. You tin can be confident that what you see locally will exist the aforementioned as yous see remotely.

            PS51> $scriptBlock = {     [version](Become-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name 'PowerShellVersion').PowerShellVersion } PS51> Invoke-Command -ComputerName 10.0.0.v -ScriptBlock $scriptBlock -Credential $cred  Major  Pocket-size  Build  Revision PSComputerName -----  -----  -----  -------- -------------- 5      1      17763  1        10.0.0.5          

Showing the aforementioned version locally and remotely is proficient. Just I've got a meliorate way to show y'all using the $PSVersionTable automatic variable.

Check Powershell Version via $PSVersionTable.PSVersion control

The last and final method is referencing the PSVersion holding on the $PSVersionTable automatic variable. This method will always stand for the PowerShell engine.

            PS51> $PSVersionTable.PSVersion  Major  Small-scale  Build  Revision -----  -----  -----  -------- v      i      17134  858          

The $PSVersionTable automatic variable is a read-simply hash table that returns data specifically almost the PowerShell engin version. This automatic variable not merely returns the version but likewise PSEdition. This property can either Core or Desktop to provide further data on the edition of PowerShell that is running.

$PSVersionTable output
$PSVersionTable output

$PSVersionTable on Remote Computers

Using the $PSVersionTable automated variable is accurate locally as it is remotely. You tin see below that past wrapping $PSVersionTable.PSVersion in a scriptblock and executing that code on a remote calculator, it volition render the aforementioned version.

            PS> Invoke-Control -ComputerName 10.0.0.5 -ScriptBlock {$PSVersionTable.PSVersion} -Credential $cred  Major  Minor  Build  Revision PSComputerName -----  -----  -----  -------- -------------- five      ane      17763  592      x.0.0.5          

Summary

In this weblog post, yous take learned all of the means to check the version of PowerShell both locally and remotely. I hope the first few methods gave y'all an thought on which ways non to check the version!

I recommend always using $PSVersionTable.PSVersion. All of the other methods may announced similar to the PowerShell engine version but may not ever reverberate the engine version.

If I missed any manner, please let me know in the comments. I'll be glad to update the post and requite you credit.

grantwhionstan.blogspot.com

Source: https://adamtheautomator.com/powershell-version/

0 Response to "how to know what version of powershell i have"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel