Error using powershell.exe: 'Select-Object' is not recognized
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
inl1ner
el 2 de Nov. de 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}
Respuestas (0)
Ver también
Categorías
Más información sobre Use COM Objects in MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!