Powershell找到服务器操作系统

LT-*_*LT- 3 powershell operating-system find windows-server

我有一项任务是找到我们在AD中为某些Microsoft许可证要求提供的所有服务器的操作系统.

有没有人这样做过?

LT-*_*LT- 6

我想到了.

请随意使用并修改它.如果您有任何疑问,请告诉我.

这是一个简单的命令.希望它可以帮助某人.这为您提供了您拥有的操作系​​统类型.我正在基于Windows Server和活动的计算机帐户进行过滤.然后按名称排序并选择唯一的OS.

Get-ADComputer -Filter {(OperatingSystem -like "*windows*server*") -and (Enabled -eq "True")} -Properties OperatingSystem | Sort Name | select -Unique OperatingSystem
Run Code Online (Sandbox Code Playgroud)

输出:

OperatingSystem
---------------
Windows Server 2012 R2 Standard
Windows Server 2008 R2 Standard
Windows Server 2012 R2 Standard Evaluation
Windows Server 2008 R2 Enterprise
Run Code Online (Sandbox Code Playgroud)

下一个命令是获取所有服务器并显示其操作系统.我再次基于Windows服务器操作系统和活动计算机帐户进行过滤.我按操作系统排序我的列表:

Get-ADComputer -Filter {(OperatingSystem -like "*windows*server*") -and (Enabled -eq "True")} -Properties OperatingSystem | sort OperatingSystem | ft DNSHostName, OperatingSystem
Run Code Online (Sandbox Code Playgroud)

您还可以将上述内容保存在变量中,然后获取每个操作系统类别中的服务器数:

$Servers = Get-ADComputer -Filter {(OperatingSystem -like "*windows*server*") -and (Enabled -eq "True")} -Properties OperatingSystem | Sort Name

$servers | group operatingsystem  
Run Code Online (Sandbox Code Playgroud)