Need help with running a script to create 100 different Sharepoint subsites

Hello.  Please let me preface this with I'm very new to Powershell and Sharepoint scripting.  So please forgive me for using incorrect terms. I was able to find online and piece together a script that will do 3 things mainly. Create a subsite from a custom template, Adds a navigation link to the subsite on the parent site, and then once created deletes certain navigation links from the subsite.  There's a few other things that are specified such as URL, Name, and Description.

I need to create about 100 more subsites hopefully using this script. Other than copying the script 100 times and changing the different URLs,names, and descriptions.  Is it possible to maybe have the script read from say a text file or list of some kind to pull the information?  Please see the script below and any assistance at all is greatly appreciated. Thanks for your time.

Add-PSSnapin Microsoft.Sharepoint.Powershell

#Create Client Subsite using Client Template
$web = get-spweb https://portal.com/Clients
$newweb = New-SPWeb -Url https://portal.com/Clients/ARC03 -Name "Archer Well Services" -UsePArentTopNav -Description "Archer Well Services"
$newweb.ApplyWebTemplate('{C475636E-5800-4210-B3EE-D9BCB0209FD1}#CLIENT_TEMPLATE_2015-07-08')

$qlNav = $web.Navigation.QuickLaunch
$qlHeading = $qlNav | where { $_.Title -eq "Clients" }
$linkNode = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode("Archer Well Services", "https://portal.com/Clients/ARC03", $true)
$qlHeading.Children.AddAsLast($linkNode)

Start-Sleep -s 2

#Create array of links that you want to delete after the site has been created. The array contains the link names.
$linksToDelete = @('Project Template - GP Upgrade', 'Test Project Template 1', 'Misc Support Project Template', 'AX Implementation Project Template')
#For each link, delete it from the Quick Launch menu            
foreach($dnname in $linksToDelete)
{
$webURL = "https://portal.com/Clients/ARC03"
$web=Get-SPWeb $webURL
$ql=$web.Navigation.QuickLaunch
$dn = $web.Navigation.QuickLaunch | where { $_.Title -eq $dnname }
if($dn -eq $null){continue;}            
 Write-Host "Deleting navigation node, $dnname"            
    #If the node wasn't null, delete it!
$ql.Delete($dn);
#Update (save) the navigation
$web.Update();
}



  • Moved by Bill_Stewart Friday, August 21, 2015 8:16 PM Move to more appropriate forum
August 21st, 2015 7:44pm

Thank you so much for this Viktor.  I will test this out and let you know how it goes.  I did have another question.

In the 2nd part of my script I use another foreach statement.  How do I use the 2 together? I'm guessing I would only need to use 1 script block (curly braces) instead of 2?  Again thanks for your time and help.

foreach ($site in $import)

foreach($dnname in $linksToDelete)

Free Windows Admin Tool Kit Click here and download it now
August 24th, 2015 4:13pm

Hi Tnofam,

Is Viktor's suggestion working for you?

Thanks

September 1st, 2015 10:48pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics