magritton
11/27/2015 - 11:28 PM

Create a sound intranet sub site using powershell

Create a sound intranet sub site using powershell

$site = Get-SPweb "http://scushp01"

$mList=$site.Lists["Branches"]
$i = 1

foreach($f in $mList.Items)
{
    $nospace = $f["Title"].Replace(" ","")
    $title = $f["Title"]
    $i
    $nospace
    $i++
        ########################################
    $web = get-spweb http://scushp01/Branches
    $template = $web.WebTemplate
    $newUrl = 'http://scushp01/Branches/' + $nospace
    $newWeb = New-SPWeb -Url $newUrl -Name $nospace
    $newWeb.ApplyWebTemplate($template)
    $w = Get-SPWeb  $newUrl
    $w.Title = $title
    $w.Update()

    ##Backup a list
    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
    $SourceWebURL = "http://scushp01/IT"
    $SourceListURL = "/IT/Lists/SiteLinks"
    $BackupPath = "C:\temp\"

    Export-SPweb $SourceWebURL -IncludeVersions All -ItemUrl $SourceListURL -path ($BackupPath + "SiteLinks.cmp") -nologfile -Force

    ##add the main backup site to the main site.
    Add-PSSnapin Microsoft.SharePoint.PowerShell
    $TargetWebURL = $newUrl
    $BackupPath = "C:\temp\SiteLinks"
    import-spweb $TargetWebURL -IncludeUserSecurity -path ($BackupPath + ".cmp") -nologfile -UpdateVersions Overwrite

}
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
########################################
$web = get-spweb http://scushp01/Branches
$newWeb = New-SPWeb -Url 'http://scushp01/Branches/Auburn' -Name "Auburn"
$newWeb.ApplyWebTemplate($template)
$w = Get-SPWeb  'http://scushp01/Branches/Auburn'
$w.Title = "Auburn"

##Backup a list
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$SourceWebURL = "http://scushp01/IT"
$SourceListURL = "/IT/Lists/SiteLinks"
$BackupPath = "C:\temp\"

Export-SPweb $SourceWebURL -IncludeVersions All -ItemUrl $SourceListURL -path ($BackupPath + "SiteLinks.cmp") -nologfile -Force

##add the main backup site to the main site.
Add-PSSnapin Microsoft.SharePoint.PowerShell
$TargetWebURL = "http://scushp01/Branches/Auburn"
$BackupPath = "C:\temp\SiteLinks"
import-spweb $TargetWebURL -IncludeUserSecurity -path ($BackupPath + ".cmp") -nologfile -UpdateVersions Overwrite