Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 341 Vote(s) - 3.42 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to find the Windows version from the PowerShell command line

#1
How do I find which Windows version I'm using?

I'm using PowerShell 2.0 and tried:

PS C:\> ver
The term 'ver' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify tha
t the path is correct and try again.
At line:1 char:4
+ ver <<<<
+ CategoryInfo : ObjectNotFound: (ver:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

How do I do this?
Reply

#2
Windows PowerShell 2.0:

$windows = New-Object -Type PSObject |
Add-Member -MemberType NoteProperty -Name Caption -Value (Get-WmiObject -Class Win32_OperatingSystem).Caption -PassThru |
Add-Member -MemberType NoteProperty -Name Version -Value [Environment]::OSVersion.Version -PassThru

Windows PowerShell 3.0:

$windows = [PSCustomObject]@{
Caption = (Get-WmiObject -Class Win32_OperatingSystem).Caption
Version = [Environment]::OSVersion.Version
}

For display (both versions):

"{0} ({1})" -f $windows.Caption, $windows.Version
Reply

#3
$OSVersion = [Version](Get-ItemProperty -Path "$($Env:Windir)\System32\hal.dll" -ErrorAction SilentlyContinue).VersionInfo.FileVersion.Split()[0]

On Windows 10 returns: 10.0.10586.420

You can then use the variable to access properties for granular comparison

$OSVersion.Major equals 10
$OSVersion.Minor equals 0
$OSVersion.Build equals 10586
$OSVersion.Revision equals 420

Additionally, you can compare operating system versions using the following

If ([Version]$OSVersion -ge [Version]"6.1")
{
#Do Something
}
Reply

#4
This will give you the **full version of Windows (including Revision/Build number)** unlike all the solutions above:

(Get-ItemProperty -Path c:\windows\system32\hal.dll).VersionInfo.FileVersion

Result:

10.0.10240.16392 (th1_st1.150716-1608)


Reply

#5
As MoonStom says, `[Environment]::OSVersion` doesn't work properly on an upgraded Windows 8.1 (it returns a Windows 8 version): [link][1].

If you want to differentiate between Windows 8.1 (6.3.9600) and Windows 8 (6.2.9200), you can use `(Get-CimInstance Win32_OperatingSystem).Version` to get the proper version. However this doesn't work in PowerShell 2. So use this:

$version = $null
try {
$version = (Get-CimInstance Win32_OperatingSystem).Version
}
catch {
$version = [System.Environment]::OSVersion.Version | % {"{0}.{1}.{2}" -f $_.Major,$_.Minor,$_.Build}
}

[1]:

[To see links please register here]

Reply

#6
Since you have access to the .NET library, you could access the [`OSVersion`][1] property of the [`System.Environment`][2] class to get this information. For the version number, there is the `Version` property.

For example,

PS C:\> [System.Environment]::OSVersion.Version

Major Minor Build Revision
----- ----- ----- --------
6 1 7601 65536

Details of Windows versions can be found [here][3].

[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

Reply

#7
1. To get the Windows version number, as Jeff notes in his [answer][1], use:

[Environment]::OSVersion

It is worth noting that the result is of type [`[System.Version]`][2], so it is possible to check for, say, Windows 7/Windows Server 2008 R2 and later with

[Environment]::OSVersion.Version -ge (new-object 'Version' 6,1)

However this will not tell you if it is client or server Windows, nor the name of the version.

2. Use WMI's [`Win32_OperatingSystem`][3] class (always single instance), for example:

(Get-WmiObject -class Win32_OperatingSystem).Caption

will return something like

> Microsoft® Windows Server® 2008 Standard

[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

Reply

#8
Use:

Get-WmiObject -class win32_operatingsystem -computer computername | Select-Object Caption
Reply

#9
If you want to differentiate between Windows 8.1 (6.3.9600) and Windows 8 (6.2.9200) use

(Get-CimInstance Win32_OperatingSystem).Version

to get the proper version. `[Environment]::OSVersion` doesn't work properly in Windows 8.1 (it returns a Windows 8 version).
Reply

#10
This will give you the full and CORRECT (the same version number that you find when you run winver.exe) version of Windows (including revision/build number) REMOTELY unlike all the other solutions (tested on Windows 10):

Function Get-OSVersion {
Param($ComputerName)
Invoke-Command -ComputerName $ComputerName -ScriptBlock {
$all = @()
(Get-Childitem c:\windows\system32) | ? Length | Foreach {

$all += (Get-ItemProperty -Path $_.FullName).VersionInfo.Productversion
}
$version = [System.Environment]::OSVersion.Version
$osversion = "$($version.major).0.$($version.build)"
$minor = @()
$all | ? {$_ -like "$osversion*"} | Foreach {
$minor += [int]($_ -replace".*\.")
}
$minor = $minor | sort | Select -Last 1

return "$osversion.$minor"
}
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through