I need to create a Site collection under that I need three subsites, For example, Demo, is site collection inside that I need to create Departments, Contact, etc. Then inside department subsite, I need to create three subsites for ex IT support, financial,HR,etc. How can I achieve this Site structure by using Powershell scripts,I referred this link PowerShell script to create hundreds of sub sites, But I need more Reference for that? Please Suggest some idea?
1 Answer
I have tested this and it works fine ! This will do what you want to achieve.
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq$null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
$SiteList = @("Department","Contact")
foreach($site in $SiteList){
New-SPWeb –url http://Demo/$site -name "$site" -Template STS#0 –AddToTopNav –UniquePermissions –UseParentTopNav
if($site -eq "Department"){
$Departments = @("IT support","Financial","HR")
foreach($Department in $Departments){
New-SPWeb –url http://Demo/$site/$Department -name "$Department" -Template STS#0 –AddToTopNav –UniquePermissions –UseParentTopNav
}
}
elseif($site -eq "Contact"){
$Contacts = @("Contact1","Contact2","Contact3")
foreach($contact in $Contacts){
New-SPWeb –url http://Demo/$site/$contact -name "$contact" -Template STS#0 –AddToTopNav –UniquePermissions –UseParentTopNav
}
}
}
-
Thanks for the reply Sam, How to choose a different template for the subsite?– DebuggerNov 4, 2016 at 4:59
-
Subsites are created only in site collection, Inside Department subsites no other subsites created, Because it throws an error for template creation,"The term template is not Recognized"@sam– DebuggerNov 4, 2016 at 5:15
-
Hi Suriya the above code works fine just make sure there is no spaces in the code– samNov 4, 2016 at 6:26
-
-
HI @Suriya I have edited the code u just need to copy and paste it and run. It works fine.– samNov 5, 2016 at 11:14