13 Mar 2009 Leave a comment
This is another PowerShell automation blog post 🙂
Setup a blank site (that is: “Sorry site is down for maintenance”) on all the front end servers and stop all existing web applications with a minimum of work. Likewise take it down easily.
By taking it down I mean deleting it so there is no risk that “someone” (the ghost in the server) might activate it by accident.
One script running on one server will install the blank site to multiple front-end servers.
When you need to take down your sites for maintenance the right thing to do is to setup some temporary site – otherwise your visitors might easily see a semi-functioning site or a huge ugly exception when you’re in the middle of something.
This is not a big task to do manually, however it is tedious if you have many front-end servers and/or many web applications.
This is a bunch of powershell scripts that is started by two batch files – one for installing the blank site and one for uninstalling. The tasks performed during installation/setup of blank site are:
For each web server (defined as arguments to the PowerShell script within the batch file):
- Stop all running websites
- Setup a new web site (named “Blank Site” on port 80, path “c:\inetpub\wwwroot\blanksite” – customize yourself)
- Copy all the files (html, aspx, css, etc..) that goes into the blank site to the newly created directory
When you uninstall the blank site the same tasks are executed in reverse order. If there is more than one blank site on the server (i.e. you happened to run the _InstallBlankSite.bat file twice) they will all be deleted by the _UninstallBlankSite.bat script.
These scripts are used by me on my SharePoint farms; however it can be used on any type of (IIS) web server setup. I’ve tested it with IIS 6 but I believe it should work with IIS 5 and upwards.
You need to edit the two batch files with the correct servernames for your farm. You may add as many as you like (separate with spaces)
I recommend that you run the scripts on a server with PowerShell installed that is not an actual front-end server. I consider it fairly bad practice to install PowerShell on the front-end servers – I only install it on the backend CA/index server.
I use one of MS’ vbs scripts from IIS6 to do interact with the IIS. Another option is to use WMI, but only if you are either only accessing local server or using PowerShell 2.0. I’ve included that script in my package, so there is no requirement that the server executing the PowerShell scripts has an IIS server installed. Not sure if it’s actually legal, but I have a hard time seeing the harm done.
The uninstall script will start all stopped/paused websites regardless if they were actually running before you started the whole thing.
If you can’t get it to work at all, check your execution policy.
The following scripts are included
_InstallBlankSite.bat: Main script to execute the dependent scripts. It will start powershell, and you need to add your server names here.
_UninstallBlankSite.bat: Main script to remove blank site. You need to add your servernames here.
InstallBlankSiteOnServers.ps1: Given a blank site and list of servers do the magic and call dependent scripts.
StopAllWebsites.ps1: Stop all running websites on a given server.
CreateBlankSite.ps1: Create a new website on server with the given local path (does not copy files).
UninstallBlankSiteOnServers.ps1: Remove a blank site from a list of servers. Assumes a local path to files.
StartAllWebSites.ps1: Start all stopped websites on a (remote) server.
DeleteBlankSite.ps1: Removes the blank site(s) from the IIS on the specified server (UninstallBlankSiteOnServers.ps1 deletes the files).
BlankSite: (Directory) the files that constitute your blank site. You’ll want to make it prettier but you get the point from what’s in there.
IISWeb.vbs: IIS script file for IIS6 from Microsoft that performs all IIS management tasks. It has not been altered in any way, it’s merely there for convenience. You’ll find it in system32 on your webservers.