Created
January 12, 2011 05:51
-
-
Save tarnacious/775756 to your computer and use it in GitHub Desktop.
IIS7 website configuration script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An example PowerShell script demonstrating configuring a website in IIS7 | |
# | |
# | |
# Import the required IIS administration module | |
# | |
Import-Module WebAdministration | |
# | |
# Lets have a look at what's setup in IIS. | |
# | |
Get-Item IIS:\\Sites\* | |
Get-Item IIS:\\AppPools\* | |
# | |
# Delete the site and app pool, will error if site doesn't exist. | |
# | |
Remove-Item IIS:\Sites\MySite -r | |
Remove-Item IIS:\AppPools\MyAppPool -r | |
# | |
# Create an app pool | |
# | |
New-Item IIS:\AppPools\MySite | |
Set-ItemProperty IIS:\AppPools\MySite -Name "managedRuntimeVersion" -Value "v4.0" | |
# | |
# Create a site | |
# | |
New-Item IIS:\Sites\MySite -bindings @{protocol="http";bindingInformation=":80:MySite" } | |
Set-ItemProperty IIS:\Sites\MySite -Name physicalPath -Value "C:\wwwroot\MySite" | |
Set-ItemProperty IIS:\Sites\MySite -Name applicationPool -Value MySite | |
# | |
# Create a virtual application | |
# | |
New-Item IIS:\Sites\MySite\MyVirtualApp -physicalPath "C:\wwwroot\MyVirtualApp" -type Application | |
# | |
# Create a virtual directory | |
# | |
New-Item IIS:\Sites\MySite\MyVirtualDir -physicalPath "C:\wwwroot\MyVirtualDir" -type VirtualDirectory | |
# | |
# Additional stuff | |
# | |
# Set user account for application pool | |
Set-ItemProperty IIS:\AppPools\MySite -Name processModel -Value @{userName="domain\user";password="password";identitytype=3} | |
# Set user account for virtual directory | |
Set-ItemProperty IIS:\Sites\MySite\MyVirtualDir -Name username -Value "domain\user" | |
Set-ItemProperty IIS:\Sites\MySite\MyVirtualDir -Name password -Value "password" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment