How to Call/Invoke PowerShell from Python

Saravanansdp
Jul 16, 2022

--

Hi There!

There are Few times, we need to call Powershell or shell script from python, In order to accomplish some requirements.

In this Article, I will be explaining about to call Powershell from python.

you need subprocess library to run the external codes from python. e.g C++, Powershell, Shell scripting. Even to open Git bash.

Code:

import subprocess, sys

def invoke_powershell():

p=subprocess.Popen([“powershell.exe”,”C:\\Project_work\\powershell_code.ps1"])
p.communicate()

#call function

invoke_powershell()

--

--