导出 Windows 操作系统版本号
我们想要获取所有 AD 计算机内部版本号的列表。那是因为我们想知道所有计算机是否都是最新的。获取此报告的一个绝佳方法是使用 PowerShell。在本文中,您将了解如何将 Windows 操作系统版本号导出到 CSV 文件。
您可以从以下位置获取版本和操作系统内部版本号关于Windows屏幕 (温弗)。
这是在 Windows Server 2019 上。
这是在 Windows 10 上。
但您想为每个系统执行此操作吗?不,你不知道。所以 PowerShell 就是答案。
导出 Windows 操作系统内部版本号 PowerShell 脚本
Get-WindowsOSBuilds.ps1 PowerShell 脚本循环遍历每台计算机,测试其是否在线,如果在线,则检查 WinRM 是否已启用。如果启用 WinRM,该脚本将检索版本、版本和操作系统内部版本。
该脚本收集每台 AD 计算机的以下信息:
- 计算机名
- 地位
- WinRM
- 版
- 版本
- 操作系统构建
重要的:Windows 远程管理服务需要在每台计算机上运行才能检索信息。这可以通过部署 GPO 或其他替代方案来完成。
另请阅读:SD 卡符号:存储卡上的数字和字母的含义
您可以通过以下名称来识别 WinRM 服务:
- 服务名称:WinRM
- 显示名称:Windows 远程管理(WS-管理)
准备 Get-WindowsOSBuilds PowerShell 脚本
在域控制器上创建两个文件夹(中:)驾驶:
- 温度
- 脚本
下载 Get-WindowsOSBuilds.ps1 PowerShell 脚本并将其放入C:脚本文件夹。该脚本会将 CSV 文件导出到C:温度文件夹。
另一种选择是将以下代码复制并粘贴到记事本中。给它起个名字获取 WindowsOSBuilds.ps1并将其放置在C:脚本文件夹。
<#
.SYNOPSIS
Get-WindowsOSBuilds.ps1
.DESCRIPTION
Export Windows OS versions and build numbers to CSV file.
.LINK
www.alitajran.com/export-windows-os-build-numbers
.NOTES
Written by: ALI TAJRAN
Website: www.alitajran.com
LinkedIn: linkedin.com/in/alitajran
.CHANGELOG
V1.00, 04/16/2023 - Initial version
#>
# Retrieve a list of all computers in the domain
$computers = Get-ADComputer -Filter { OperatingSystem -Like "Windows*" }
# Set the registry path that will be used to retrieve the Windows build numbers
$regPath = "HKLM:SOFTWAREMicrosoftWindows NTCurrentVersion"
# Initialize progress bar
$total = $computers.Count
$completed = 0
$progress = 0
Write-Progress -Activity "Retrieving Windows build numbers" -Status "Starting..." -PercentComplete $progress
# Loop through each computer and retrieve the Windows versions and build numbers (if the computer is online)
$results = foreach ($computer in $computers) {
$computerName = $computer.Name
$online = Test-Connection -ComputerName $computerName -Count 1 -Quiet
if ($online) {
$winRMEnabled = $null -ne (Test-WSMan -ComputerName $computerName -ErrorAction SilentlyContinue)
if ($winRMEnabled) {
$buildNumber = (Invoke-Command -ComputerName $computerName { (Get-ItemProperty -Path $using:regPath -Name "CurrentBuild").CurrentBuild })
$revisionNumber = (Invoke-Command -ComputerName $computerName { (Get-ItemProperty -Path $using:regPath -Name "UBR").UBR })
$windowsBuildNumber = "$buildNumber.$revisionNumber"
$edition = (Invoke-Command -ComputerName $computerName { (Get-ItemProperty -Path $using:regPath -Name "ProductName").ProductName })
$version = (Invoke-Command -ComputerName $computerName { (Get-ItemProperty -Path $using:regPath -Name "ReleaseID" -ErrorAction Stop).ReleaseID })
}
else {
$windowsBuildNumber = "N/A"
$edition = "N/A"
$version = "N/A"
}
[PSCustomObject] @{
"ComputerName" = $computerName
"Status" = "Online"
"WinRM" = if ($winRMEnabled) { "Enabled" } else { "Disabled" }
"Edition" = $edition
"Version" = $version
"OSBuild" = $windowsBuildNumber
}
}
else {
[PSCustomObject] @{
"ComputerName" = $computerName
"Status" = "Offline"
"WinRM" = "N/A"
"Edition" = "N/A"
"Version" = "N/A"
"OSBuild" = "N/A"
}
}
$completed++
$progress = [Math]::Round($completed / $total * 100)
Write-Progress -Activity "Retrieving Windows build numbers" -Status "Completed $completed of $total" -PercentComplete $progress
}
# Sort the results by ComputerName in ascending order and select only the desired columns
$results | Sort-Object ComputerName | Select-Object ComputerName, Status, WinRM, Edition, Version, OSBuild | Export-Csv -Path "C:TempWindowsOSBuilds.csv" -NoTypeInformation
这就是它的样子。
运行 Get-WindowsOSBuilds PowerShell 脚本
使用 PowerShell 获取所有 AD 计算机的 Windows 操作系统版本。更改脚本文件夹的路径。之后,运行脚本 Get-WindowsOSBuilds.ps1。
PS C:> cd c:scripts
PS C:scripts> .Get-WindowsOSBuilds.ps1
打开 Windows 操作系统构建报告 CSV 文件
Get-WindowsOSBuilds.ps1 PowerShell 脚本会将 Active Directory 计算机内部版本号导出到 CSV 文件。找到文件WindowsOSBuilds.csv在路径中C:温度。
使用您喜欢的应用程序打开 CSV 文件。在我们的示例中,它是 Microsoft Excel。
Windows 操作系统构建报告看起来非常出色。
重要的:如果组织中有这样的政策,请不要忘记禁用 Windows 远程管理 (WinRM)。
这是否可以帮助您将 Windows 操作系统版本号导出到 CSV 文件?
结论
您学习了如何使用 PowerShell 导出 Windows 操作系统版本号。使用 Get-WindowsOSBuilds PowerShell 脚本获取 Windows 操作系统构建报告并进行查看。出于安全目的,请确保所有 Windows AD 计算机都是最新的。
您喜欢这篇文章吗?您可能还喜欢使用 PowerShell 脚本检查 Windows 上的可用磁盘空间。不要忘记关注我们并分享这篇文章。
