[Python] Dynamic variable in the PowerShell command with \4 to be executed in the python code...

Discussão em 'Python' iniciado por Stack, Julho 7, 2025.

  1. Stack

    Stack Membro Participativo

    I am writing a python code which involves executing 2 PowerShell commands. 1st one gets the value from the device and then passes that value to the next powershell command. 1st Command: 'Get-PnpDevice -FriendlyName "CastlePeak" | Select-Object -ExpandProperty InstanceId'.format(friendly_name) Output of 1st Command: PCI\VEN_1414&DEV_B301&SUBSYS_B3011414&REV_00\4&36AB8B&0&0010 Second Command: 'Get-PnpDevice -InstanceId "{}" | Get-PnpDeviceProperty -KeyName "DEVPKEY_Device_BiosDeviceName" | Select-Object -ExpandProperty Data'.format(instance_id) where the value of instance is the output of the command 1.

    When I run the command directly in to the device on PowerShell it retrieves the value, whereas when I do it in the python code, it does not.

    Log screenshot of my run

    Continue reading...

Compartilhe esta Página