0

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

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? – Suriya Nov 4 '16 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 – Suriya Nov 4 '16 at 5:15
  • Hi Suriya the above code works fine just make sure there is no spaces in the code – sam Nov 4 '16 at 6:26
  • ya sure let me check, shall we discuss in chat @Sam – Suriya Nov 4 '16 at 6:42
  • HI @Suriya I have edited the code u just need to copy and paste it and run. It works fine. – sam Nov 5 '16 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.