0

I have a requirement where I need to do some service restarts and iisreset using python on a couple of remote servers. I have managed to write py code for service restarts using WMI but not able to find any module or solution for doing iisreset.

I know how to do an IIS reset using PowerShell remoting but need it specifically for python. One solution I can think of is making a bat file, copying it on a remote server and executing that bat file as admin using psExec or WMI but would prefer if any module is there for handling IIS-related operations.

  1. I found one module(called iis_bridge) but not sure if it allows working on a remote server. Any thoughts/suggestions?

  2. Also suppose we opened WMI connection to a remote server, do we need to close the wmi connection? I looked into a couple of WMI related documents but none had information to close WMI connection. Is it not needed?

  • Does this answer your question? [Python: Using wmi to start executable remotely](https://stackoverflow.com/questions/29659469/python-using-wmi-to-start-executable-remotely) – Guenther Schmitz Feb 27 '22 at 17:35
  • Please provide enough code so others can better understand or reproduce the problem. – Community Feb 27 '22 at 20:30
  • Hi Guenther, nope I am aware how i can execute files remotely using wmi.. what i was looking for is some python module or inbuilt method which can be used to perform iis reset on remote servers. – Piyush Garg Feb 28 '22 at 03:33
  • I also found the module iis_bridge. The docs provides the command to reset IIS. `is.iisreset()` You can try it. But I prefer you to use python to call other bat files or powershell scripts to do this. I can't understand the risks of using iis_bridge, but I can confirm that the native powershell and command line of windows are safer. – Bruce Zhang Feb 28 '22 at 05:38
  • Yeah, is.iisreset is working for local computer but not sure how I can pass it for remote server as it is not mentioned in the document too that it supports over remote sessions.. Looks like I might have to go with bat files only but lets see if someone else knows the solution. Thanks for your efforts!! :) – Piyush Garg Feb 28 '22 at 09:04

0 Answers0