2

I know it might sound weird because I can do it using PowerShell, but I'd like to use Python to find what Windows Features are enabled.

I'll explain my reason and maybe you'll be able to guide me in a different direction, because from a quick google search, what I'm looking for is not possible.

I have a script that should be able to run on both Windows and Linux. It checks if a path to a directory exists, and if I have permissions to it. It does a bunch of other things and since it should work on both OSes, I need it to check that Windows Features thing. I don't want to run two different scripts, I'd rather have it all in one place and I'm not sure if maybe I'm able to call PowerShell inside my script.

Any idea what I can do?

Daniel
  • 621
  • 5
  • 22
  • Does this answer your question? [Run PowerShell function from Python script](https://stackoverflow.com/questions/14508809/run-powershell-function-from-python-script) – funie200 Jan 20 '20 at 16:37
  • So basically I can't do this without creating a .ps1 file inside the same folder right? I was wondering if there's a way around that and just do it all inside the same script. – Daniel Jan 20 '20 at 16:44

1 Answers1

0

I tried to search myself how to get the enabled windows features and found nothing, but i have some solution for you. In my opinion you can run a powershell script inside your python script and get the result in a variable in you python script using subprocess module:

import subprocess
p = subprocess.Popen(["powershell.exe",
          r"C:\Path\powershellscript.ps1"],
          stdout=subprocess.PIPE)

output, err = p.communicate()
print(output)

The output variable will contain the data i believe you desire

Doron Shevach
  • 133
  • 1
  • 11