[英]Powershell to find Server Operating system
I had a task to find Operating System of all the servers we had in AD for some Microsoft Licenses requirement. 我有一项任务是找到我们在AD中为某些Microsoft许可证要求提供的所有服务器的操作系统。
Has anyone done this? 有没有人这样做过?
I figured it out. 我想到了。
Please feel free to use it and modify it. 请随意使用并修改它。 If you have questions, let me know.
如果您有任何疑问,请告诉我。
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.
我正在基于Windows Server和活动的计算机帐户进行过滤。 Then sort by name and select unique OS.
然后按名称排序并选择唯一的OS。
Get-ADComputer -Filter {(OperatingSystem -like "*windows*server*") -and (Enabled -eq "True")} -Properties OperatingSystem | Sort Name | select -Unique OperatingSystem
Output: 输出:
OperatingSystem
---------------
Windows Server 2012 R2 Standard
Windows Server 2008 R2 Standard
Windows Server 2012 R2 Standard Evaluation
Windows Server 2008 R2 Enterprise
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.
我再次基于Windows服务器操作系统和活动计算机帐户进行过滤。 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
$OSIs64BitArch = ([System.Environment]::Is64BitOperatingSystem)
$OSArchString = if ( $OSIs64BitArch ) {"x64"} else {"x86"}
$OSIsServerVersion = if ([Int]3 -eq [Int](Get-WmiObject -Class Win32_OperatingSystem).ProductType) {$True} else {$False}
$OSVerObjectCurrent = [System.Environment]::OSVersion.Version
if ($OSVerObjectCurrent -ge (New-Object -TypeName System.Version -ArgumentList "6.1.0.0")) {
if ($OSVerObjectCurrent -ge (New-Object -TypeName System.Version -ArgumentList "6.2.0.0")) {
if ($OSVerObjectCurrent -ge (New-Object -TypeName System.Version -ArgumentList "6.3.0.0")) {
if ($OSVerObjectCurrent -ge (New-Object -TypeName System.Version -ArgumentList "10.0.0.0")) {
if ( $OSIsServerVersion ) {
Write-Output ('Windows Server 2016 ' + $OSArchString + " ... OR Above")
} else {
Write-Output ('Windows 10 ' + $OSArchString + " ... OR Above")
}
} else {
if ( $OSIsServerVersion ) {
Write-Output ('Windows Server 2012 R2 ' + $OSArchString)
} else {
Write-Output ('Windows 8.1 ' + $OSArchString)
}
}
} else {
if ( $OSIsServerVersion ) {
Write-Output ('Windows Server 2012 ' + $OSArchString)
} else {
Write-Output ('Windows 8 ' + $OSArchString)
}
}
} else {
if ( $OSIsServerVersion ) {
Write-Output ('Windows Server 2008 R2 ' + $OSArchString)
} else {
Write-Output ('Windows 7 OR Windows 7-7601 SP1' + $OSArchString)
}
}
} else {
Write-Output ('This version of Windows is not supported.')
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.