Error using powershell.exe: 'Select-Object' is not recognized
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
inl1ner
am 2 Nov. 2023
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}
Antworten (0)
Siehe auch
Kategorien
Mehr zu Use COM Objects in MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!