So now we are going to look at creating a simple array and then iterating through it, creating sites and lists as we go.
Line 1 creates an array with 3 values, Maths, English and Science.
Line 2 says, for each value in the array do the following.
Line 3 – 15 will create the site and lists in the same way I talked about in the last two posts.
I have tried to be a little clever in the creation of the sites by using the values within the array to name the lists and the site which is what the variable $sitename is for.
$sites = ("Maths", "English", "Science") ForEach ($sitearray in $sites) { $sitename = $sitearray $SiteTitle = $SiteName + "" #in case you want to add anything else to title add it inside "" quotes. $SiteUrl = "http://intranet/" + $sitename + "/" $SiteTemplate = "STS#1" Write-Host "Creating new site at" $SiteUrl $NewSite = New-SPWeb -URL $SiteUrl -Template $SiteTemplate -Name $SiteTitle -UseParentTopNav $web = Get-SPWeb $SiteUrl $web.Lists.Add($sitename + " Announcements", $sitename + " site announcements list", 104) $web.Lists.Add($sitename + " Links", $sitename + " site links list", 103) $web.Lists.Add($sitename + " Documents", $sitename + " site documents library", 101) $web.Lists.Add($sitename + " Pictures", $sitename + " site picture library", 109) }
I hope this will help someone along with the rest of the series and is certainly a good reference for myself.