How can I run Windows PowerShell commands from Python? [duplicate]

Using the subprocess library it’s possible to run CMD commands within Python. In order to run powershell commands, all you’d need to do is execute C:\Windows\System32\powershell.exe and pass through the arguments.

Here’s some example code to try:

import subprocess

subprocess.call('C:\Windows\System32\powershell.exe Get-Process', shell=True)

You can replace “Get-Process” with the PowerShell command you need

Leave a Comment