While converting and merging some SharePoint sites, I created some PowerShell scripts to speed up the process.
In case I’ll ever need them again, I post them here:
Script 1: Mount a Content database using PowerShell
Script 2: Generate a sub site using PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$url = "http://tfssharepoint/sites/defaultcollection/mynewsite" | |
$projectname = "mynewsite" | |
New-SPWeb -url $url -Name $projectname -Template "Microsoft.TeamFoundation.Sharepoint.Dashboards#0" |
Script 3: Generate a Document Library using PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createDocumentLibrary ($webUrl, $libraryName) | |
{ | |
# varable description | |
$web = Get-SPWeb $webUrl | |
$libraryDescription = "" | |
$libraryTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary; | |
# Adding Library | |
try | |
{ | |
$web.Lists.Add($libraryName,$libraryDescription,$libraryTemplate); | |
$web.Update(); | |
} | |
catch | |
{ | |
write-host "Error" $_.exception | |
$errorlabel = $true | |
} | |
finally | |
{ | |
if($web -ne $null) | |
{ | |
$web.Dispose() | |
} | |
} | |
} | |
$webUrl = "http://tfssharepoint/sites/defaultcollection/mynewsite" | |
$libraryName = "Shared Documents" | |
createDocumentLibrary -webUrl $webUrl -libraryName $libraryName |
Script 4: Remove a site collection(without asking for confirmation) using PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$url= "http://tfssharepoint/sites/defaultcollection/sitetoremove" | |
Remove-SPSite $url -confirm:$false |