How to find the Windows version from the PowerShell command line

前端 未结 25 1095
野的像风
野的像风 2020-12-22 15:51

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 o         


        
25条回答
  •  萌比男神i
    2020-12-22 16:24

    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 
    

提交回复
热议问题