Error using powershell.exe: 'Select-Object' is not recognized

21 ビュー (過去 30 日間)
Stijn Haenen
Stijn Haenen 2021 年 3 月 31 日
コメント済み: inl1ner 2023 年 11 月 2 日
I want to get information about serial ports via the powershell.
I got the results i want, when I write some line of code in command Window:
system("powershell")
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\Users\> Get-CimInstance -Class Win32_SerialPort | Select-Object Name, Description, DeviceID, PNPDeviceID
Get-CimInstance -Class Win32_SerialPort | Select-Object Name, Description, DeviceID, PNPDeviceID
Name Description DeviceID PNPDeviceID
---- ----------- -------- -----------
Arduino Uno (COM4) Arduino Uno COM4 USB\VID_2341&PID_0043\55737313331351A00212
Arduino Micro (COM38) Arduino Micro COM38 USB\VID_2341&PID_8037&MI_00\7&2D66C3B6&0&0000
PS C:\Users\> exit
But when I run the same commands in a single line or as function, i get an error:
>> system("powershell Get-CimInstance -Class Win32_SerialPort | Select-Object Name, Description, DeviceID, PNPDeviceID")
'Select-Object' is not recognized as an internal or external command,
operable program or batch file.
I think that the second part of the command (after the | ) is not executed in the powershell but in the cmd. How can I solve this?
  1 件のコメント
inl1ner
inl1ner 2023 年 11 月 2 日
In PowerShell funktioniert es so:
$GetPort = Get-CimInstance -ClassName Win32_PNPEntity |
Select-Object -Property Caption, $StatusInfo
Write-Host $GetPort
@{Name=Kommunikationsanschluss (COM1); Description=Kommunikationsanschluss; DeviceID=COM1; PNPDeviceID=ACPI\PNP0501\0}

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeUse COM Objects in MATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by