jra*_*ara 106 windows powershell powershell-2.0
如何找到我正在使用的Windows版本?
我正在使用PowerShell 2.0并尝试:
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
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?
Jef*_*ado 148
由于您可以访问.NET库,因此可以访问该类的OSVersion属性System.Environment以获取此信息.对于版本号,Version有财产.
例如,
PS C:\> [System.Environment]::OSVersion.Version
Major Minor Build Revision
----- ----- ----- --------
6 1 7601 65536
Run Code Online (Sandbox Code Playgroud)
可以在此处找到Windows版本的详细信息.
Ric*_*ard 100
要获得Windows版本号,正如杰夫在他的回答中所说,使用:
[Environment]::OSVersion
Run Code Online (Sandbox Code Playgroud)
值得注意的是,结果是类型的[System.Version],因此可以检查,例如,Windows 7/Windows Server 2008 R2及更高版本
[Environment]::OSVersion.Version -ge (new-object 'Version' 6,1)
Run Code Online (Sandbox Code Playgroud)
但是,这不会告诉您它是客户端还是服务器Windows,也不会告诉您版本的名称.
使用WMI的Win32_OperatingSystem类(总是单个实例),例如:
(Get-WmiObject -class Win32_OperatingSystem).Caption
Run Code Online (Sandbox Code Playgroud)
将返回类似的东西
Microsoft®WindowsServer®2008标准版
Ant*_*lov 39
不幸的是,大多数其他答案都没有提供Windows 10特有的信息.
Windows 10有自己的版本:1507,1511,1607,1703等.这是winver显示的.
Powershell:
(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId
Command prompt (CMD.EXE):
Reg Query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ReleaseId
Run Code Online (Sandbox Code Playgroud)
另请参阅有关超级用户的相关问题.
至于其他Windows版本使用systeminfo.Powershell包装:
PS C:\> systeminfo /fo csv | ConvertFrom-Csv | select OS*, System*, Hotfix* | Format-List
OS Name : Microsoft Windows 7 Enterprise
OS Version : 6.1.7601 Service Pack 1 Build 7601
OS Manufacturer : Microsoft Corporation
OS Configuration : Standalone Workstation
OS Build Type : Multiprocessor Free
System Type : x64-based PC
System Locale : ru;Russian
Hotfix(s) : 274 Hotfix(s) Installed.,[01]: KB2849697,[02]: KB2849697,[03]:...
Run Code Online (Sandbox Code Playgroud)
Windows 10输出相同的命令:
OS Name : Microsoft Windows 10 Enterprise N 2016 LTSB
OS Version : 10.0.14393 N/A Build 14393
OS Manufacturer : Microsoft Corporation
OS Configuration : Standalone Workstation
OS Build Type : Multiprocessor Free
System Type : x64-based PC
System Directory : C:\Windows\system32
System Locale : en-us;English (United States)
Hotfix(s) : N/A
Run Code Online (Sandbox Code Playgroud)
小智 24
Get-WmiObject -Class Win32_OperatingSystem | ForEach-Object -MemberName Caption
Run Code Online (Sandbox Code Playgroud)
或者打高尔夫球
gwmi win32_operatingsystem | % caption
Run Code Online (Sandbox Code Playgroud)
结果
Microsoft Windows 7 Ultimate
Iho*_*ich 17
这将为您提供完整版本的Windows(包括版本/内部版本号),与上述所有解决方案不同:
(Get-ItemProperty -Path c:\windows\system32\hal.dll).VersionInfo.FileVersion
Run Code Online (Sandbox Code Playgroud)
结果:
10.0.10240.16392 (th1_st1.150716-1608)
Run Code Online (Sandbox Code Playgroud)
小智 12
从PowerShell 5开始:
Get-ComputerInfo
Get-ComputerInfo -Property Windows*
Run Code Online (Sandbox Code Playgroud)
我认为这个命令几乎尝试了迄今为止发现的1001种收集系统信息的方法......
PS C:\> Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer
Run Code Online (Sandbox Code Playgroud)
退货
WindowsProductName WindowsVersion OsHardwareAbstractionLayer
------------------ -------------- --------------------------
Windows 10 Enterprise 1709 10.0.16299.371
Run Code Online (Sandbox Code Playgroud)
如果要区分Windows 8.1(6.3.9600)和Windows 8(6.2.9200)使用
(Get-CimInstance Win32_OperatingSystem).Version
Run Code Online (Sandbox Code Playgroud)
获得正确的版本.[Environment]::OSVersion在Windows 8.1中无法正常工作(它返回Windows 8版本).
我正在完善其中一个答案
我在尝试匹配winver.exe的输出时遇到了这个问题:
Version 1607 (OS Build 14393.351)
我能够用以下内容提取构建字符串:
,((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name BuildLabEx).BuildLabEx -split '\.') | % { $_[0..1] -join '.' }
Run Code Online (Sandbox Code Playgroud)
结果: 14393.351
更新:这是一个使用正则表达式的略微简化的脚本
(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").BuildLabEx -match '^[0-9]+\.[0-9]+' | % { $matches.Values }
Run Code Online (Sandbox Code Playgroud)
如果您尝试破译 MS 在其修补网站上发布的信息,例如https://technet.microsoft.com/en-us/library/security/ms17-010.aspx
您将需要一个组合,例如:
$name=(Get-WmiObject Win32_OperatingSystem).caption
$bit=(Get-WmiObject Win32_OperatingSystem).OSArchitecture
$ver=(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId
Write-Host $name, $bit, $ver
微软 Windows 10 家庭版 64 位 1703
除了其他答案之外,以下是一些可以使用 PowerShell 检索的有用信息:
\n通过PowerShell查询操作系统和硬件信息:
\n查询通用OS(操作系统)信息:
\n查看操作系统名称的最快方法:
\ncmd ?\nRun Code Online (Sandbox Code Playgroud)\n#使用获取计算机信息:
\nGet-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer\nRun Code Online (Sandbox Code Playgroud)\n#使用 Get-WmiObject:
\n$name=(Get-WmiObject Win32_OperatingSystem).caption\n$bit=(Get-WmiObject Win32_OperatingSystem).OSArchitecture\n$ver=(Get-ItemProperty "HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion").ReleaseId\nWrite-Host " OS-Name: `t $name `n Architct: `t $bit `n Release: `t $ver" \nRun Code Online (Sandbox Code Playgroud)\n列出主要次要版本信息:
\n[System.Environment]::OSVersion.Version \nRun Code Online (Sandbox Code Playgroud)\n查询主机名:
\n$Env:ComputerName\nRun Code Online (Sandbox Code Playgroud)\n或者
\nhostname #cmd command\nRun Code Online (Sandbox Code Playgroud)\n另外,如果您知道 IP 地址,请使用“ping”命令(例如:),ping /a <your_ip_address>您将在第一行看到您的“主机名”。
查询当前(登录)用户:
\nwhoami #cmd command\nRun Code Online (Sandbox Code Playgroud)\n或者
\n[System.Security.Principal.WindowsIdentity]::GetCurrent().Name \nRun Code Online (Sandbox Code Playgroud)\n查询映射驱动器: \n列出映射驱动器 - 使用 WMI:
\nGet-WmiObject -Class Win32_LogicalDisk | Format-Table \nRun Code Online (Sandbox Code Playgroud)\n或者
\nwmic logicaldisk get name #list just logical-drive letters\nRun Code Online (Sandbox Code Playgroud)\n或者,列出逻辑驱动器信息:FreeSpace、Provider(真实网络位置)、Size 和 VolumeName:
\nwmic logicaldisk list brief\nRun Code Online (Sandbox Code Playgroud)\n列出映射驱动器 - 使用 [DriveInfo] 类:
\n[System.IO.DriveInfo]::GetDrives()\nRun Code Online (Sandbox Code Playgroud)\n列出可移动驱动器:
\n$drives = [System.IO.DriveInfo]::GetDrives()\n$r = $drives | Where-Object { $_.DriveType -eq 'Removable' -and $_.IsReady }\nif ($r) {\n return @($r)[-1]\n}\nRun Code Online (Sandbox Code Playgroud)\n查询磁盘容量、空间和卷类型
\nInvoke-Command -ComputerName S1 {Get-PSDrive C} | Select-Object PSComputerName,Used,Free \nRun Code Online (Sandbox Code Playgroud)\n可用空间:
\n(Get-PSDrive C).Free\nRun Code Online (Sandbox Code Playgroud)\n或(以 GB 为单位)
\n[Math]::Floor(((Get-PSDrive C).Free /[Math]::Pow(2, 30)*10)) /10\nRun Code Online (Sandbox Code Playgroud)\n已用空间:
\n(Get-PSDrive C).Used\nRun Code Online (Sandbox Code Playgroud)\nOR(已用空间,以 GB 为单位)
\n[Math]::Floor(((Get-PSDrive C).Used /[Math]::Pow(2, 30)*10)) /10\nRun Code Online (Sandbox Code Playgroud)\n另外要查看总空间:(以 GB 为单位)
\n$totalSpace = ((Get-PSDrive C).Used + (Get-PSDrive C).Free)/(1024*1024*1024)\nOR\n$totalSpace = ((Get-PSDrive C).Used + (Get-PSDrive C).Free)/[Math]::Pow(2, 30)\nRun Code Online (Sandbox Code Playgroud)\n四舍五入值:
\n[Math]::Floor($totalSpace*10) / 10\nOR\n[Math]::Round($totalSpace,1)\nRun Code Online (Sandbox Code Playgroud)\n查询主板信息:
\nwmic baseboard get product,Manufacturer,version,serialnumber\nRun Code Online (Sandbox Code Playgroud)\n查询磁盘卷(磁盘分区)信息: \nGet-Volume 返回有关存储驱动器分区的信息,例如:
\nGet-Volume # All partitions\nGet-Volume -DriveLetter C # Specific partition\nRun Code Online (Sandbox Code Playgroud)\n#文件系统类型:
\nGet-Volume -DriveLetter C | select FileSystem\n(Get-Volume -DriveLetter C).FileSystem\nRun Code Online (Sandbox Code Playgroud)\n#分区大小:
\nGet-Volume -DriveLetter C | select Size\nOR (in GB)\n[Math]::Floor(((Get-Volume -DriveLetter C).Size/[Math]::Pow(2, 30)*10)) /10\nRun Code Online (Sandbox Code Playgroud)\n查询内存/查询 RAM
\nGet-WmiObject Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum\nOR (in GB)\n$memory = (Get-WmiObject Win32_PhysicalMemory | Measure -Property Capacity -Sum).Sum\n$memory = [Math]::Floor(($memory/[Math]::Pow(2, 30)*10)) /10\n$memory.ToString() + " gb"\nRun Code Online (Sandbox Code Playgroud)\n#查询RAM包括频率/速度:
\nGet-CimInstance win32_physicalmemory | Format-Table Manufacturer,Banklabel,Configuredclockspeed,Devicelocator,Capacity,Serialnumber \xe2\x80\x93autosize\nRun Code Online (Sandbox Code Playgroud)\n如前所述,这个答案有点超出了所提出的问题,但对于那些想要使用 PowerShell 获取其他操作系统或硬件信息的人来说可能很有用。
\n小智 5
我接受了上面的脚本,并对它们进行了一些微调,以得出以下结论:
$name=(Get-WmiObject Win32_OperatingSystem).caption
$bit=(Get-WmiObject Win32_OperatingSystem).OSArchitecture
$vert = " Version:"
$ver=(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId
$buildt = " Build:"
$build= (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").BuildLabEx -match '^[0-9]+\.[0-9]+' | % { $matches.Values }
$installd = Get-ComputerInfo -Property WindowsInstallDateFromRegistry
Write-host $installd
Write-Host $name, $bit, $vert, $ver, `enter code here`$buildt, $build, $installd
Run Code Online (Sandbox Code Playgroud)
要获得这样的结果:
Microsoft Windows 10 Home 64位版本:1709内部版本:16299.431 @ {WindowsInstallDateFromRegistry = 18-01-01 2:29:11 AM}
提示:我希望能从安装日期中删除前缀文本,以便可以用可读性更高的标题替换它。
小智 5
要在 Windows 10 1809 上的 PowerShell v5 中生成与 winver.exe 相同的输出:
$Version = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\'
"Version $($Version.ReleaseId) (OS Build $($Version.CurrentBuildNumber).$($Version.UBR))"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
328474 次 |
| 最近记录: |