Skip to content
Advertisement

How do I run a PowerShell script with parameters from Python

I’m trying to run PowerShell scripts that have parameters from Python 3.7.3, but don’t know how to properly call the function in Popen

What I’m trying to do with my PowerShell script is login to Cisco routers and run Cisco IOS commands on x number of routers based on how many are defined. So the way I have my PowerShell script setup I pass in the IP address of the router like .test.ps1 177.241.87.103 when I’m using PowerShell, or powershell.test.ps1 177.241.87.103 when I’m using command prompt. Both of these commands work and get the correct output and save their outputs to text files as well.

But now I want to get Python to run this “test.ps1” script with the parameter. I’ve saved “test.ps1” to “C:Usersjgreen02” and to “C:Usersjgreen02Desktop”

JavaScript

I’m certain I’m using the call function incorrectly, or maybe the file I’m trying to run needs to be placed in the folder where my Python script is sitting.

The error output is:

JavaScript

Advertisement

Answer

2 things wrong with the approach:

code00.py:

JavaScript

script00.ps1:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement