简体   繁体   English

Powershell找到服务器操作系统

[英]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.

相关问题 Powershell Active Directory(操作系统) - Powershell Active Directory (Operating System) 使用PowerShell获取操作系统信息,将Buildnumber更改为String - Get Operating System info using PowerShell, change Buildnumber to String 将计算机主机名、操作系统以及是否启用 Bitlocker 导出为 CSV 的 PowerShell 脚本 - PowerShell script that exports to CSV the computer Hostname, operating system and if Bitlocker is enabled or not 通过操作系统驱动器 (C:\\) 上的 Powershell 使用 BitLocker 启用磁盘加密 - Enabling Disk Encryption with BitLocker Via Powershell On the Operating System Drive (C:\) 如何在 Linux 操作系统中从 Java 调用“Powershell 脚本文件” - How to Invoke "Powershell script file" from Java in Linux operating system 在应用程序内部运行PowerShell? - Operating PowerShell inside an application? PowerShell 远程操作 ComObject - PowerShell operating a ComObject remotely 错误:尝试使用 windows powershell 创建新的 angular 项目时,“您的操作系统拒绝了该操作” - Error: "The operation was rejected by your operating system" when trying to create new angular project using windows powershell 有没有办法使用Powershell从Hyper-V获取VM操作系统名称? - Is there a way to get VMs Operating System name from Hyper-V using powershell? PowerShell不支持[System.Array] :: Find方法 - [System.Array]::Find Method is not supported in powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM