pwsh command with python subprocess is not working when using IIS server

180 Views Asked by At

I am running one api using flask . in that I have a powershell script . I am calling this script in a python program using subprocess and using pwsh(because of POWERCLI which uses powershell higher version). regular powershell is not working .

cmd = " path of .ps1 "          
value  = subprocess.Popen(['pwsh',  '-Command', cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out = value.communicate()[0] 
data = json.loads(out) 

I am executing this api in windows server locally . which is working fine and giving required data. as soon as I am hosting this in IIS server. this is not giving any output.

1 -This is the error generated by python script when running from IIS . The term 'Set-PowerCLIConfiguration' is not recognized as a name of a cmdlet, function, script file, or executable program.\to Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I have already installed the powercli using : Install-Module VMware.PowerCLI -Scope AllUsers As per the error looks like powercli setting needs some thing to update for IIS . Please guide me on this

2- I tried with full path of pwsh along with .exe . but that itself got error. not sure it take pwsh.exe full path. 3- My other scripts which are using regular powershell are working fine with IIS server.

value = subprocess.Popen(['powershell', cmd], shell=True, 
stdout=subprocess.PIPE, stderr=subprocess.PIPE)

issue is when I use pwsh alog with IIS server, Is there anything I am missing or need to add in command with pwsh. I used subprocess.run also. but in IIS both are not working.

0

There are 0 best solutions below