Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

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

$
0
0

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();
}




Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>