Installing IIS Using Powershell

install IIS and websites with powershell

Are you looking to Install IIS using PowerShell? Well, I spent last week attending a course on 'Administering the web server role of Windows Server (IIS)'. It's been a dry but interesting course once again hosted by my preferred Microsoft training provider QA.

The course occasionally touched upon the use of 'PowerShell' to install and manage and manage IIS but didn't explore it in any real detail. Being curious, I decided to dig around the internet and have a go at building some 'stock' scripts for my use. So here you are, there are two scripts here for you to use if you wish;

  1. Installing IIS via a script to a nondefault file structure (something you can't do with the GUI)
  2. Create a website and application pool via a script.

What does the first script do?

Ok, the first one does the following as part of the IIS install;

  • Defines file location variables for your IIS folder structure with a location for the root folder location, log file location, and wwwroot file location
  • It Installs IIS and a variety of other 'features'. If you are unfamiliar with each of the 'shortcodes' for the features, I would recommend you refer to this 'IIS cmdlets' guide or use the 'get-WindowsFeature' command in PowerShell
  • It creates your folder structure
  • It copies any files from the 'old' inetpub location (C:\inetpub initially)
  • Sets up the standard directory permissions (you may not want this!)
  • Changes the log file and default web site location as specified in the variables section
  • Does some error checking
  • Deletes the old wwwroot folder
  • and finally, restarts the IIS service.

This script has been written and tested on/for Windows 2012 IIS8+ and is provided 'as is'. Use at your own risk.

What does the second script do?

The second script, this one creates a web site and app pool with the following;

  • It sets up the variables for nine different things. I've named these for ease of understanding.
  • Creates a website directory
  • Find the app pool root
  • Checks the app pool doesn't already exist
  • Finds the site root
  • Checks to see if the location already exists
  • Creates both the website and app pool
  • It configures the web site bindings.

Again this script has been written and tested on/for Windows 2012 IIS8+ and is provided 'as is'. Use at your own risk. I've saved these files as .txt files to use them save as .ps1 files Download

I've done this more for my reference but if it helps people then great.

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.