SQL SERVER – PowerShell Version Info

I have multiple computer systems at home. I have previously taken a picture of my home office and published it here. Also, I recently had a scenario where I was listing a PowerShell version installed in my computer systems. While searching online, I found two different commands that can determine the version of PowerShell. One of them worked fine in Version 1, while both worked on Version 2.
The commands are:

$PSVersionTable

and

$host

I have run both the commands on different PowerShell versions and found the following output. This is a call to all PowerShell experts to help me out by letting me know the reasons why these became the results. I am sure that I’m missing something very small, so I ask your help to  clarify this.

PowerShell Version 1

SQL SERVER – PowerShell Version Info powershell1

PowerShell Version 2

SQL SERVER – PowerShell Version Info powershell2

Reference : Pinal Dave (https://blog.sqlauthority.com)

Powershell, SQL Scripts
Previous Post
SQL SERVER – Index Levels, Page Count, Record Count and DMV – sys.dm_db_index_physical_stats
Next Post
SQLAuthority News – I am Microsoft Certified Trainer (MCT)

Related Posts

2 Comments. Leave new

  • Marko Parkkola
    July 5, 2010 1:18 pm

    Hi,

    You could try this.

    if (Test-Path Variable:PSVersionTable) {$PSVersionTable.PSVersion} else {[Version]”1.0.0.0″}

    $PSVersionTable exists only in PowerShell version 2 IIRC.

    Reply
  • Also:
    (Get-Item HKLM:\Software\Microsoft\PowerShell\1\PowerShellEngine).GetValue(“RuntimeVersion”)

    Reply

Leave a Reply