Running Powershell script with Python

Data Geek
1 min readAug 17, 2020

--

I had a requirement where I need to trigger an existing PowerShell script from Python. The PowerShell script is to download a file from SharePoint.
I wanted to have the output of the PowerShell script within Python script output.

It’s quite easy to do this using subprocess and sys modules.

import subprocess, sys

p = subprocess.Popen(["powershell.exe",
"C:\\Project\\downloadSharePointFile.ps1"],
stdout=sys.stdout)
p.communicate()

--

--

Data Geek

I write about Python, Unix, Data Engineering, and Automation Testing.