Question

What's the best way to create hundreds of sub sites in a site collection for testing purposes? It doesn't matter what their names are. Doing some research, I found a few scripts that either require that I enter each site's name or that I use an xml file that would still involve me manually entering hundreds of unique names for each sub site. I would just need the sub sites to automatically be named test1, test2, or follow some kind of similar pattern. There has to be some way to leverage the New-SPWeb cmdlet with a for loop maybe? Can it be done without using a config or csv file?

Was it helpful?

Solution

Below script accepts the array of the sub sites name, But you can amend it instead of passing the SubSIte name arrays just add test(i)...i mean in the for loop instead of checking the array's count, check fix the number of subsite($i <100000)...then susbite url will be like this

$SiteUrl = $SiteCollectionURL + "/test" +$i

. Copy and Paste the code below and save it as CreateSubSite.ps1, see highlighted yellow sections to change configurable values:

Add-PsSnapin Microsoft.SharePoint.PowerShell

## SharePoint DLL 
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") 

#Creating Sub Sites in top site collection.
Write-Output " "
Write-Output "Creating Sub Sites"

$SiteCollectionURL = "http://localhost/sites/SPFix"

$SiteCollectionTemplate = "STS#0" 

$SiteCollectionLanguage = 1033

$SubSites = @("Central Services", "Knowledge Base", "Service Center", "IT", "HR", "Finance")

for($i=0 ; $i -lt $SubSites.count ; $i++)
{
$SiteUrl = ""
$SiteUrl = $SiteCollectionURL + "/" 
$SiteUrl = $SiteUrl += $SubSites[$i]
Write-Output " "
#Write-Output "Creating Site for " += $SubSites[$i]
Write-Output " "
New-SPWeb $SiteUrl -Template $SiteCollectionTemplate -Name $SubSites[$i]  -UseParentTopNav -Language $SiteCollectionLanguage
Write-Output " "
#Write-Output "Site Created for " += $SubSites[$i]
Write-Output " "
}

Remove-PsSnapin Microsoft.SharePoint.PowerShell

http://www.sharepointfix.com/2011/04/powershell-script-to-create-subsites.html

OTHER TIPS

The basic syntax for creating site would be New-SPSite -Url $WebSiteUrl -OwnerAlias $SiteOwner -Name "Store" -Template $webTemplate and creating subsite `New-SPWeb -Url $WebSiteUrl -OwnerAlias $SiteOwner -Name "Store" -Template $webTemplate.

Now for your requirement I think you have to use some kind of loop and call the above syntax for that many times.

Refer this question on syntax site-provisioning-example `

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top