Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Another Look at PowerShell Core Version Information

Posted on February 8, 2018

As PowerShell Core begins to spread into our world, and as we start thinking about working and scripting cross-platform, it will be useful to know what type of platform you are running on. The built in $PSVersionTable is an obvious place to start. On PowerShell Core there are also some new built-in variables you can use.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

image

But these variables are not on Windows PowerShell. So I decided to add another tool to the mix – a simple function that will provide a snapshot look at version information, including what possible remoting options are available. This should be WinRM for Windows platforms and potentially SSH. The function isn't especially complicated.

Function Get-PSVersion {
<#
.Synopsis
Get a short view of PowerShell version information

.Description
Use this command to get a quick snapshot of PowerShell version information. The
Remoting property should indicate what remoting capabilities are potentially
available.

.Example
PS C:\> Get-PSVersion

Version      : 5.1.16299.98
Edition      : Desktop
Platform     : Windows
Remoting     : {WinRM}
Computername : Win10Desk

Running on a Windows 10 desktop.

.Example
PS C:\> Get-PSVersion


Version      : 6.0.1
Edition      : Core
Platform     : Win32NT
Remoting     : {WinRM, SSH}
Computername : SRV1

Running PowerShell Core on a Windows platform with SSH installed.

.Example
PS /mnt/c/scripts> get-psversion


Version      : 6.0.1
Edition      : Core
Platform     : Unix
Remoting     : {SSH}
Computername : Bovine320

PowerShell Core running in a Linux environment.

.Link
$PSVersionTable


#>
[cmdletbinding()]
Param()

$ver = $PSVersionTable.PSVersion
$edition = $PSVersionTable.PSEdition

if ($PSVersionTable.platform) {
    $platform = $PSVersionTable.platform
}
else {
    $platform = "Windows"
}

$remoting = @()
if (Test-Path 'WSMan:') {
    $remoting+="WinRM"
}
if (Get-Command ssh -ErrorAction SilentlyContinue) {
    $remoting+="SSH"
}

#use the hostname command because non-windows systems won't have
#$env:computername.
[pscustomobject]@{
    Version = $ver
    Edition = $edition
    Platform = $platform
    Remoting = $Remoting
    Computername = $(hostname)
}

}

Here's what it looks like on a variety of platforms.

image

 

image

image

I might package this into my PSScriptTools module.

Have you started embracing this cross-platform world? What challenges have you encountered and how have your overcome them? I'd love to hear your stories.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

3 thoughts on “Another Look at PowerShell Core Version Information”

  1. Dave Carnahan says:
    February 8, 2018 at 11:04 am

    When we start using powershell core, we’ll need to find replacement calls for Get-WMI calls.

    Any thoughts on resources to find the most common WMI objects?

    1. Jeffery Hicks says:
      February 8, 2018 at 12:08 pm

      You are not the only one to wonder about this. I think long term we’ll see something like this, which you can install now. https://github.com/Microsoft/omi

      1. Dave Carnahan says:
        February 8, 2018 at 7:50 pm

        Good deal.

        I can’t help thinking that Richard Siddaway is working this one in one form or fashion.

        It just has his name written all over it.

        Thanks Jeffery!

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d