Skip to content

Instantly share code, notes, and snippets.

@sdesalas
Last active July 14, 2020 18:44
Show Gist options
  • Save sdesalas/6533286 to your computer and use it in GitHub Desktop.
Save sdesalas/6533286 to your computer and use it in GitHub Desktop.
This script restarts IIS and configures it on a remote server. Needs Sysinternals PsExec (http://technet.microsoft.com/en-au/sysinternals/bb897553.aspx)
:: Stop IIS
PsExec.exe \\LDNSERV01 -s -i C:\windows\system32\inetsrv\appcmd.exe stop site OnlineXCart
:: Recycle App Pool (removes lock on file system)
PsExec.exe \\LDNSERV01 -s -i C:\windows\system32\inetsrv\appcmd.exe recycle apppool OnlineXCart
:: Wait 4 Seconds
:: This is useful if you have a command straight after that executes file operations on IIS App Directory
ping -n 5 127.0.0.1 > nul
:: Modify IIS Physical Path Remotely
PsExec.exe \\LDNSERV01 -s -i C:\Windows\system32\inetsrv\appcmd.exe set config -section:system.applicationHost/sites /[name='OnlineXCart'].[path='/'].[path='/'].physicalPath:"D:\websites\OnlineXCart\${WEBAPP_VERSION}\Main" /commit:apphost
:: Start IIS
PsExec.exe \\LDNSERV01 -s -i C:\windows\system32\inetsrv\appcmd.exe start site OnlineXCart
@sdesalas
Copy link
Author

Note that the user executing this command should have (admin?) access on \LDNSERV01

@agray
Copy link

agray commented Jan 7, 2016

Thanks @sdesalas, Used this in my Jenkins scripts here

@ibrahimozgon
Copy link

It works fine, thank you!

@ibrahimozgon
Copy link

Hi @sdesalas @agray,
Do you encounter any 404 problem while your ci server is deploying?
I used this code to close site and app pool. Then i copied files and started site and app pool

Our load balancer sends request to closed site and it gives 404 error.

How can i handle this? Do you have any suggestion? Do i need to change steps(site closing-app pool closing)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment