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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With