Skip to content

Instantly share code, notes, and snippets.

@karaaie
Created June 15, 2014 10:01
Show Gist options
  • Save karaaie/fa682985f0259315ae95 to your computer and use it in GitHub Desktop.
Save karaaie/fa682985f0259315ae95 to your computer and use it in GitHub Desktop.
param (
#folder where all your websites are located
[string]$webSiteRootFolder = "c:\websites",
#name of site that you're setting up
[string]$siteName = "HelloWorldSite",
#the port your default binding is using
[string]$port = 8090,
#where the source files are
[string]$Sourcefiles = "source/*"
)
import-module WebAdministration (1)
#site folder
$siteInstallLocation = "$webSiteRootFolder\$siteName"
#site application pool
$siteAppPool = "$siteName-pool"
#check if the site is already present (determines update or install)
$isPresent = Get-Website -name $siteName (2)
if($isPresent){
#upgrade the current package
Write-Host "$siteName will be updated"
Copy-Item $Sourcefiles -Recurse $siteInstallLocation -Force
}else{
#install a clean version of the package
Write-Host "$siteName will be installed"
#create site folder
new-item $siteInstallLocation -ItemType directory -Force (3)
#copy site files to site folder
Copy-Item $Sourcefiles -Recurse $siteInstallLocation -Force (4)
#create application pool
New-WebAppPool -Name $siteAppPool -Force (5)
#set the alwaysRunning setting to true.(this is needed for workflow to start properly)
#to find which path to modify look in the applicationHosts.config file (google for location)
Set-WebConfigurationProperty "/system.applicationHost/ApplicationPools/add[@name='$siteAppPool']" -PSPath IIS:\ -Name startMode -Value "AlwaysRunning" (6)
#create site
New-Website -Name $siteName -Port $port -ApplicationPool $siteAppPool -PhysicalPath $siteInstallLocation (7)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment