Wednesday, November 14, 2012

Create a Default IIS Website using PowerShell

First you will have to import module named "WebAdministration"

PS C:\> Import-Module "WebAdministration"

PS C:\> Get-Command -Module "WebAdministration"

 You can create new website, app pools, bindings with these commandlets. I have combined few commandlets and created my script which does the following:

1.  Does a remote session into a specific computer with specific credentials
2.  Imports Module WebAdministration on that server.
3.  Creates WebAppPool and set's its property.  I have parameter where you can specify .net framework.
4.  Tests physical path of the website if it doesn't exists then it creates one for you.
5.  Create Website with bindings and set's application pool to the one created in step 3.

Here is the script. Enjoy

With PowerShell V3 I do Show-command createdefaultwebsite.ps1 name and it shows me nice form to fill in the details.  I love this feature in V3.