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()

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Data Geek
Data Geek

Written by Data Geek

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

Responses (1)

Write a response