PowerShell – Identify and switch between installed PowerShell Versions

Most of the time we have been used to cmdlets and it’s various features but do not know about the version and hence this post might help some of you to understand in finding different versions of PowerShell and how to switch between versions (provided multiple versions are installed on your Machine). I’m using Where clause syntax to explain version switching.

Code to find version-

PS:\>Get-Host | Select-Object Version

Version
——-
2.0

PS:\>$Host.Version

Major  Minor  Build   Revision
—–    —–    —–    ——–
2        0         -1      -1

PS:\>$PSVersionTable.PSVersion

Major  Minor  Build   Revision
—–    —–    —–    ——–
3        0         -1      -1

Switch between versions -

Goto Cmd Prompt and type the below command

C:\> Powershell -version 2

PS C:\>Get-Host | select Version

#v2 syntax

PS C:\> Get-Service | Where {$_.name -like “*SQL*”}

Status       Name                              DisplayName
——          —-                                 ———–
Stopped   MSSQL$MICROSOFT…  Windows Internal Database (MICROSOF…
Running   SQLWriter                       SQL Server VSS Writer

PS C:\> Get-Service | where name -like “*SQL*”

Error Message -

where : Cannot bind parameter ‘FilterScript’. Cannot convert the “name” value of type “System.String” to type “System.Management.Automation.ScriptBlock”.

C:\> powershell -version 3

PS C:\> Get-Host | Select Version

PS C:\> Get-Service | where {$_.name -like “*SQL*”}

Status       Name                              DisplayName
——          —-                                 ———–
Stopped   MSSQL$MICROSOFT…  Windows Internal Database (MICROSOF…
Running   SQLWriter                       SQL Server VSS Writer

#v3 syntax

PS C:\> Get-Service | Where name -like “*SQL*”

Status       Name                              DisplayName

——          —-                                 ———–
Stopped   MSSQL$MICROSOFT…  Windows Internal Database (MICROSOF…
Running   SQLWriter                       SQL Server VSS Writer

Syntax for Where-Object

V2 Syntax : Where-Object { $_.<property name> }
V3 Syntax : Where-Object <property name> #Supports V2 syntax

PowerShell-Version

About these ads

About Prashanth Jayaram

I’m a Database technologist having 7+ years of rich, hands-on experience on Database technologies. I am Microsoft Certified Professional and backed with a Degree in Master of Computer Application. My expertise lies in T-SQL programming, Replication and PowerShell. hobbies are playing sports and drawing.
This entry was posted in PowerShell and tagged , , , , . Bookmark the permalink.

2 Responses to PowerShell – Identify and switch between installed PowerShell Versions

  1. WRONG !!!
    PowerShell is diveded into the Host Programm and PowerShell himself.
    The Host Programm is the Interface and PowerShell is the Engine build into the host Programm.
    For example do a remote session and enter Get-Host or user teh PowerGUI PowerShell Editor and enter Get-Host you will see you get the Host back not PowerShell!
    If you use Get-Host or simply the build in Variable $Host you are quering the Version of the Host NOT of the PowerShell engine!
    To correct query the PowerShell Version use the build in Variable $PSVersionTable If this Variable is not there you have powerShell Version 1.0 !

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s