Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a full PowerShell version as a single-line string?

At first glance you may be tempted to dismiss this question as something that can be easily searched, but please bear with me and read on.

I know that there are multiple ways to find the PowerShell version, but I specifically need a clean single line output without any fancy tables or new lines, that I can put into a variable.

(Get-Host).Version gives me:

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  2673

Get-Host | Select-Object Version gives me:

Version
-------
5.1.19041.2673

Get-Host | Format-List -Property Version gives me:

Version : 5.1.19041.2673

(with two new lines above and below)

Get-Host | Format-Wide -Property Version gives me the closest thing to my desire:

5.1.19041.2673

(with two new lines above and below)

Basically, I am looking for the simplest way to just get 5.1.19041.2673 in the output without any additional columns, new lines or descriptions.

like image 341
Sargon Avatar asked Oct 15 '25 02:10

Sargon


1 Answers

You can call the .ToString() method on the .Version property to get the output you're looking for:

(Get-Host).Version.ToString()

Coercing to a string would also work:

[string] (Get-Host).Version
like image 168
Santiago Squarzon Avatar answered Oct 17 '25 17:10

Santiago Squarzon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!