PowerShell 获取接在电脑上显示器的序列号,支持多个

发布时间 2023-07-27 15:01:49作者: 人生若只ru初恋
$Monitors = Get-WmiObject WmiMonitorID -Namespace root\wmi
function Decode {
    If ($args[0] -is [System.Array]) {
        [System.Text.Encoding]::ASCII.GetString($args[0])
   }
    Else {
        continue
    }
}
$result = ForEach ($Monitor in $Monitors) {  
    $Manufacturer = Decode $Monitor.ManufacturerName -notmatch 0
    $Name = Decode $Monitor.UserFriendlyName -notmatch 0
    $Serial = Decode $Monitor.SerialNumberID -notmatch 0

    $Serial
}
$result -join ","