How To Manage WebSites using PowerShell on IIS 8


As PowerShell continues to evolve and more features are added with each OS release there is more places to use PowerShell to automate and make many tasks easy. In this post we will explore managing websites using PowerShell, so let’s get started. the examples used in this post are from Cognos modifications to the default IIS 8 install.

The Code

All of the commands we will be using are part of the WebAdministration PowerShell module. Open PowerShell and import the module.

PS C:\> Import-module WebAdministration

Now we are ready to go!

Create a Virtual Directory called c10 under Default Web Site.

PS C:\> New-WebVirtualDirectory -Site "Default Web Site" -Name c10 -PhysicalPath E:\cognos102264\webcontent

Create a nested Virtual Directory under virtual directory c10.

PS C:\> New-WebVirtualDirectory -Site "Default Web Site" -Name c10\cgi-bin -PhysicalPath E:\cognos102264\cgi-bin

Set ISAPI-CGI security Settings

PS C:\> set-webconfiguration system.webserver/security/isapiCGIRestriction -value "True"

Define an new isapicgiRestriction to allow unspecified CGI and ISAPI modules.

PS C:\> Add-WebConfiguration /system.webServer/security/isapiCgiRestriction -value @{description="cognos.cgi";path="E:\cognos102264\cgi-bin\cognos.cgi";allowed="True"}

Add cgi module handler

PS C:\> New-WebHandler -Name CGI-server -Path *.cgi -Verb * -Modules CgiModule -PSPath "IIS:\sites\Default Web Site\cgi-bin"

Convert to application

PS C:\> ConvertTo-WebApplication "IIS:\Sites\Default Web Site\c10\cgi-bin"

Create Application Pool

PS C:\> New-WebAppPool -Name ""

Set HTTP Redirect

PS C:\> Set-WebConfiguration system.webServer/httpRedirect "IIS:\sites\Default Web Site" -Value @{enabled="true";destination="/c10";httpResponseStatus="Found"}


As we can see with PowerShell we can create websites, virtual directoyies, application pools and modify other settings.


Leave a Reply

Your email address will not be published. Required fields are marked *

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