本文介绍了Powershell 查找服务器操作系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是查找我们在 AD 中拥有的所有服务器的操作系统,以满足某些 Microsoft 许可证要求.

I had a task to find Operating System of all the servers we had in AD for some Microsoft Licenses requirement.

有人做过吗?

推荐答案

我想通了.

请随意使用和修改.如果您有任何问题,请告诉我.

Please feel free to use it and modify it. If you have questions, let me know.

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

It's a simple command. Hopefully, it helps someone. This gives you the type of operating systems you have. I am filtering based on Windows Server only and computer accounts that are active. Then sort by name and select unique OS.

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

输出:

OperatingSystem
---------------
Windows Server 2012 R2 Standard
Windows Server 2008 R2 Standard
Windows Server 2012 R2 Standard Evaluation
Windows Server 2008 R2 Enterprise

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

Next command is to get all the servers and show their Operating System. Again, I am filtering based on Windows server OS and Active computer accounts. I am sorting my list by Operating system:

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

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

You can also save the above in a variable and then get the count of Servers in each operating system category:

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

$servers | group operatingsystem

这篇关于Powershell 查找服务器操作系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 15:38