【问题标题】:Get-WMIObject powershell获取 WMIObject PowerShell
【发布时间】:2021-10-30 16:42:24
【问题描述】:

我在 powershell 中有我的代码来打印 COM 端口

    Set-ExecutionPolicy Bypass -Scope CurrentUser
try {
Get-WMIObject Win32_SerialPort | Select-Object DeviceID, PNPDeviceID | Where-Object{$_.PNPDeviceID -like "*$env:asset*"} 
}
catch{
    Write-Warning "Nessuna porta COM trovata, assicurarsi che il dispositivo sia correttamente collegato"
    $LASTEXITCODE = 1
    exit $LASTEXITCODE
}

这是结果:

DeviceID PNPDeviceID                                                                                             
-------- -----------                                                                                             
COM4     BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0000\7&2A34F9CE&0&000000000000_00000006         
COM3     BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_VID&000101E6_PID&1128\7&2A34F9CE&0&000780F5F461_C00000000

我只是想让它显示这个:

DeviceID                                                                                             
--------                                                                                              
COM4              
COM3 

我怎样才能得到这个结果? 感谢您的建议!

【问题讨论】:

  • 您明确告诉它将这两个属性放入您的新对象中 >>> Select-Object DeviceID, PNPDeviceID 咧嘴]

标签: powershell printing bluetooth com wmi


【解决方案1】:

尝试通过以下代码更改第三行。

(Get-WMIObject Win32_SerialPort |
    Select-Object DeviceID, PNPDeviceID |
    Where-Object{$_.PNPDeviceID -like "*$env:asset*"}).DeviceID

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-04
    • 2017-08-20
    • 1970-01-01
    • 2014-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多