ค้นหาเวอร์ชันและรุ่นของระบบปฏิบัติการ Windows ใน Active Directory
มาดูหลายวิธีในการจัดทำเวอร์ชันสินค้าคงคลังและการสร้างระบบปฏิบัติการ Windows ในโดเมน Active Directory (โดยเฉพาะอย่างยิ่งมีความเกี่ยวข้องสำหรับ Windows 10) หากคุณไม่มีเครื่องมือใดๆ เพื่อรับการกำหนดค่าคอมพิวเตอร์โดยอัตโนมัติ เช่น SCCM, GLPI ที่มี FusionInventory หรืออย่างน้อยโฮสต์ Windows Server Update (WSUS) (นอกจากนี้ยังช่วยให้คุณได้รับเวอร์ชัน Windows บนคอมพิวเตอร์ที่ค้นพบ) คุณสามารถใช้ สคริปต์ PowerShell เพื่อค้นหาเวอร์ชัน/รุ่นของ Windows บนคอมพิวเตอร์โดเมน
บนคอมพิวเตอร์แบบสแตนด์อโลน คุณสามารถรับเวอร์ชัน Windows และหมายเลขบิวด์ได้จากรีจิสทรีหรือจาก SystemInfo:
Get-ItemProperty 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion' | Select-Object ProductName, ReleaseID, CurrentBuildGet-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayerหากต้องการดูรายการคอมพิวเตอร์ที่ใช้งานอยู่ในโดเมน Active Directory และเวอร์ชันของ Windows (รุ่น) บนคอมพิวเตอร์เหล่านั้น คุณสามารถใช้ Get-ADComputers cmdlet
อย่าลืมปิดการใช้งานและลบบัญชีคอมพิวเตอร์ที่ไม่ได้ใช้งานในโดเมนของคุณเป็นประจำ
ตรวจสอบให้แน่ใจว่าได้ติดตั้งโมดูล Active Directory สำหรับ PowerShell บนคอมพิวเตอร์ของคุณแล้ว และเรียกใช้คำสั่งด้านล่าง:
Get-ADComputer -Filter {(Enabled -eq $True)} -Property * | Select-Object Name,OperatingSystem,OperatingSystemVersionในการแปลงหมายเลขบิลด์ของ Windows 10 และ 11 เป็นรูปแบบที่สะดวกกว่า (21H1, 21H2 เป็นต้น) คุณต้องใช้ฟังก์ชันเพิ่มเติม
function ConvertWindowsBuild{
[CmdletBinding()]
param(
[string] $OperatingSystem,
[string] $OperatingSystemVersion
)
if (($OperatingSystem -like '*Windows 10*') -or ($OperatingSystem -like 'Windows 11*')) {
$WinBuilds= @{
'10.0 (22621)' = "Windows 11 22H2"
'10.0 (19045)' = "Windows 10 22H2"
'10.0 (22000)' = "Windows 11 21H2"
'10.0 (19044)' = "Windows 10 21H2"
'10.0 (19043)' = "Windows 10 21H1"
'10.0 (19042)' = "Windows 10 20H2"
'10.0 (18362)' = "Windows 10 1903"
'10.0 (17763)' = "Windows 10 1809"
'10.0 (17134)' = "Windows 10 1803"
'10.0 (16299)' = "Windows 10 1709"
'10.0 (15063)' = "Windows 10 1703"
'10.0 (14393)' = "Windows 10 1607"
'10.0 (10586)' = "Windows 10 1511"
'10.0 (10240)' = "Windows 10 1507"
'10.0 (18898)' = 'Windows 10 Insider Preview'
}
$WinBuild= $WinBuilds[$OperatingSystemVersion]
}
else {$WinBuild = $OperatingSystem}
if ($WinBuild) {
$WinBuild
} else {
'Unknown'
}
}จากนั้น หากต้องการดูรายการเวอร์ชัน Windows พร้อมชื่อโฮสต์ หมายเลขบิลด์ ที่อยู่ IP และการเข้าสู่ระบบโดเมนล่าสุดของคอมพิวเตอร์ ให้เรียกใช้สคริปต์ PowerShell ต่อไปนี้:
$Comps= Get-ADComputer -Filter {(Enabled -eq $True)} -properties *
$CompList = foreach ($Comp in $Comps) {
[PSCustomObject] @{
Name = $Comp.Name
IPv4Address = $Comp.IPv4Address
OperatingSystem = $Comp.OperatingSystem
Build = ConvertWindowsBuild -OperatingSystem $Comp.OperatingSystem -OperatingSystemVersion $Comp.OperatingSystemVersion
LastLogonDate = $Comp.LastLogonDate
}
}
$CompList | Out-GridViewคุณสามารถแสดงผลเป็นตาราง Out-GridView หรือส่งออกรายการคอมพิวเตอร์เป็นไฟล์ CSV (
Export-Csv -Path .\windows_version_report.csv -NoTypeInformation).
หากต้องการแสดงสถิติโดยสรุปในคอมพิวเตอร์หลายเครื่องที่มี Windows รุ่นต่างๆ และรุ่นในโดเมนของคุณ:
$CompList | Group-Object -Property Build | Format-Table -Property Name, Countคุณยังสามารถสอบถามคอมพิวเตอร์ของคุณจากระยะไกลและรับเวอร์ชัน Windows โดยใช้ PowerShell Remoting วิธีนี้ช้ากว่า แต่ช่วยให้คุณได้รับเวอร์ชัน Windows บนคอมพิวเตอร์ในสภาพแวดล้อมแบบเวิร์กกรุ๊ป (PSRemoting ในเวิร์กกรุ๊ป) ในการรับข้อมูลจากคอมพิวเตอร์ระยะไกล คุณสามารถใช้ Invoke-Command cmdlet:
Invoke-Command -ScriptBlock {Get-ItemProperty 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion' | Select-Object ProductName, ReleaseID, CurrentBuild} -ComputerName wsk-w12b21| Select-Object PSComputerName,ProductName, ReleaseID, CurrentBuild
คุณสามารถรับเวอร์ชัน Windows บนคอมพิวเตอร์หลายเครื่องตามรายการในไฟล์ TXT:
Invoke-Command -ComputerName (Get-Content c:\ps\PC_list.txt) -ScriptBlock {Get-ItemProperty 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion' | Select-Object ProductName, ReleaseID, CurrentBuild}|Select-Object PSComputerName,ProductName, ReleaseID, CurrentBuildคุณสามารถใช้สคริปต์ Powershell เหล่านี้เพื่อรับเวอร์ชัน Windows และสร้างบนคอมพิวเตอร์โดเมน ค้นหาคอมพิวเตอร์ที่มี Windows 10 รุ่นเก่า (ไม่รองรับ) และอัปเดต (จะอัปเดต Windows 10 Build ด้วย Command-Line ได้อย่างไร)




