Friday, August 27, 2010

create a bunch of websites using POSH

#########################################################
#
# Script to Create the websites in all tiers.
#
# Created Aug 20, 2010
# Bryan Loveless 
#
#
# Requires Powershell 2.0
#
# Change your Execution policy to RemoteSigned if running locally
# by: Set-executionpolicy -executionpolicy RemoteSigned
#
#Prereqs: Have physical paths created already.  
#    Also must have at least one site that exists.  Keep the "Default" 
#        one for now.
#
########################################################
import-module webadministration

$physicalpath = "C:\Projects\Websites" 

#New-Item iis:\Sites\$sitename -bindings @{protocol="http";bindingInformation=":80:$sitename"} -physicalPath $physicalpath\$sitename

#list all websites below, IIS names are same as Physical Paths ON PURPOSE!

$listofwebsites = "site1","site2","site3","YouGetTheIdeaRight","wehavelotsmore","butforthisblog","IshortendTheList"

foreach ($site in $listofwebsites)
{
#create the site, associate with physical path. WILL OVERWRITE OLD SITE!
New-Item iis:\Sites\$site -bindings @{protocol="http";bindingInformation="*:80:"} -physicalPath $physicalpath\$site -Force

#Adds the HTTPS port to all sites.

New-WebBinding -Name "$site" -IP "*" -Port 443 -Protocol https

#stop the site after creating it
Stop-Website $site
}

# to see what a site has, try:
# get-webbinding -name "NAMEOFSITE"

No comments:

Post a Comment