为什么ManufacturerName和UserFriendlyName不完整?

时间:2019-06-20 20:51:53

标签: powershell get-wmiobject

运行此脚本:

$FormatEnumerationLimit =-1
Get-WmiObject WmiMonitorID -Namespace root\wmi
$Monitors = Get-WmiObject WmiMonitorID -Namespace root\wmi
$LogFile = "C:\Users\monkeygead\Desktop\monitors.txt"

"Manufacturer,Name,Serial"

ForEach ($Monitor in $Monitors)
{
    $Manufacturer = ($Monitor.ManufacturerName -notmatch 0 | ForEach{[char]$_}) -join ""
    $Name = ($Monitor.UserFriendlyName -notmatch 0 | ForEach{[char]$_}) -join ""
    $Serial = ($Monitor.SerialNumberID -notmatch 0 | ForEach{[char]$_}) -join ""

    "$Manufacturer,$Name,$Serial"
}

正在输出:

  

DEL,DELL U415,CV9N64604TL
  DEL,戴尔U415,CV9N81S1C6S

为什么制造商报告为DEL而不是DELL,而型号报告为DELL U415而不是DELL U2415?

1 个答案:

答案 0 :(得分:1)

使用您的代码,我还会得到部分残缺的数据,

SAM,SycMastr,H9XQ900000
SAM,SycMastr,H1AK500000

this answer的我的情况并非如此

$FormatEnumerationLimit =-1
Get-WmiObject WmiMonitorID -Namespace root\wmi
$Monitors = Get-WmiObject WmiMonitorID -Namespace root\wmi
$LogFile = Join-Path ([Environment]::GetFolderPath('Desktop')) "monitors.csv"

$Data = ForEach ($Monitor in $Monitors){
   [PSCustomObject]@{
           Manufacturer = (-join [char[]] $Monitor.ManufacturerName)
           Name         = (-join [char[]] $Monitor.UserFriendlyName)
           Serial       = (-join [char[]] $Monitor.SerialNumberID)
    }
}

$Data
# $Data | Out-Gridview
# $Data | Export-Csv $LogFile -NoTypeInformation

Manufacturer     Name          Serial
------------     ----          ------
SAM              SyncMaster    H9XQ000000
SAM              SyncMaster    H1AK500000