Win32_ComputerOperatingSystem类提供了关于你机器上安装的操作系统的详细信息。下面的这些例子是从这里转换过来的。
# ServicePack 版本 Get-CimInstance -ClassName Win32_OperatingSystem | select ServicePackMajorVersion, ServicePackMinorVersion # 操作系统的安装日期 Get-CimInstance -ClassName Win32_OperatingSystem | select Installdate # Windows 版本 Get-CimInstance -ClassName Win32_OperatingSystem | select Caption, Version # windows 目录 Get-CimInstance -ClassName Win32_OperatingSystem | select WindowsDirectory # 所有的信息 Get-CimInstance -ClassName Win32_OperatingSystem | select Caption, Version, ServicePackMajorVersion, ServicePackMinorVersion, Installdate, WindowsDirectory
你也可以创建一个函数:
function get-OS { [CmdletBinding()] param( [string]$computername = $env:COMPUTERNAME ) Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName $computername| select Caption, Version, ServicePackMajorVersion, ServicePackMinorVersion, Installdate, WindowsDirectory }
然后选择你需要的属性:
PS> get-OS | Format-Table Caption, Installdate Caption Installdate ------- ----------- Microsoft Windows Server 2012 R2 Datacenter 1/7/2014 10:58:02 AM PS> get-OS Caption : Microsoft Windows Server 2012 R2 Datacenter Version : 6.3.9600 ServicePackMajorVersion : 0 ServicePackMinorVersion : 0 Installdate : 1/7/2014 10:58:02 AM WindowsDirectory : C:\Windows PS> get-OS | Format-Table Caption, Installdate -AutoSize Caption Installdate ------- ----------- Microsoft Windows Server 2012 R2 Datacenter 1/7/2014 10:58:02 AM
原文作者:Richard Siddaway
原文链接:Win32_OperatingSystem examples
本文链接: https://www.pstips.net/get-os-info-by-win32_operatingsystem.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!
楼主你好,我执行你的code出现如下错误,请问我是不是少了操作?求指导!
PS C:\> get-OS
无法将“Get-CimInstance”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请
检查名称的拼写,如果包括路径,请确保路径正确,然后重试。
所在位置 C:\1.ps1:7 字符: 16
+ Get-CimInstance <<<< -ClassName Win32_OperatingSystem -ComputerName $comput
ername|
+ CategoryInfo : ObjectNotFound: (Get-CimInstance:String) [], Com
mandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Get-CimInstance 是PowerShell3.0的命令,你尝试用Get-WmiObject替换吧
你好,我将获取AD中计算机的操作系统的位数,是32位还是64位,应该用什么命令,感谢。
你既然是域管理员,先查询Get-ADComputer 返回机器名称,再使用本文中的函数。