Skip to content

Instantly share code, notes, and snippets.

@ifrahim
Created February 26, 2014 15:31
Show Gist options
  • Save ifrahim/9231677 to your computer and use it in GitHub Desktop.
Save ifrahim/9231677 to your computer and use it in GitHub Desktop.
Create IIS Site using Powershell
# The following code will create an IIS site and it associated Application Pool.
# Please note that you will be required to run PS with elevated permissions.
# Visit http://ifrahimblog.wordpress.com/2014/02/26/run-powershell-elevated-permissions-import-iis-module/
# set-executionpolicy unrestricted
$SiteFolderPath = "C:\WebSite" # Website Folder
$SiteAppPool = "MyAppPool" # Application Pool Name
$SiteName = "MySite" # IIS Site Name
$SiteHostName = "www.MySite.com" # Host Header
New-Item $SiteFolderPath -type Directory
Set-Content $SiteFolderPath\Default.htm "<h1>Hello IIS</h1>"
New-Item IIS:\AppPools\$SiteAppPool
New-Item IIS:\Sites\$SiteName -physicalPath $SiteFolderPath -bindings @{protocol="http";bindingInformation=":80:"+$SiteHostName}
Set-ItemProperty IIS:\Sites\$SiteName -name applicationPool -value $SiteAppPool
# Complete
@margani
Copy link

margani commented Jun 5, 2018

Thank you. How can you create a new website but in stopped state?

@JoshuaCarroll
Copy link

@margani I think you'll find it is stopped by default. (At least mine was.)

@henrytran9x
Copy link

How to edit config Application Pool existed in IIS using Powershell ? thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment