Error using powershell.exe: 'Select-Object' is not recognized
21 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
inl1ner
le 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}
Réponses (0)
Voir également
Catégories
En savoir plus sur Use COM Objects in MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!