Skip to content

Instantly share code, notes, and snippets.

@mutuadavid93
Last active August 22, 2017 07:21
Show Gist options
  • Save mutuadavid93/057f24d42e1e516923f329f26f2270d4 to your computer and use it in GitHub Desktop.
Save mutuadavid93/057f24d42e1e516923f329f26f2270d4 to your computer and use it in GitHub Desktop.
NB: The SiteCollection is Created automatically. If you try to make the collection first
an Exception will be thrown; "The Site Collection Already Exists".
NB: You don't need the -HostHeaderWebApplication parameter if the site being restored, share
the same name as the web application.
### Backup
Backup-SPSite http://s-hqs-spdev/sites/branding/ -Path C:\COLLECTIONS\Branding.bak –UseSqlSnapshot
### Restore with a named contentDatabase
Restore-SPSite -Identity http://s-hqs-spstagsvr/sites/branding -Path "C:\COLLECTIONS\Branding.bak" -ContentDatabase MyDB -Verbose
### Restore To a Named WebApplication
Restore-SPSite -Identity http://s-hqs-spdev/sites/stb -Path "C:\COLLECTIONS\Branding.bak" -HostHeaderWebApplication http://s-hqs-spdev/ -Force -Verbose
###
Restore-SPSite -Identity "http://s-hqs-spdev/sites/ourbrand" -Path "C:\COLLECTIONS\Branding.bak" -Force -Verbose
### List all site collections in a webApplication into a txt file
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
Get-SPWebApplication http://s-hqs-spdev | Get-SPSite | Select ID, Url | Out-File -FilePath "C:\spSites.txt"
## Get All Sub-Sites of a Site Collection.
$siteColl = Get-SPSite http://yoursite/collection
$sitecoll.Allwebs > c:\SubSites.txt
## Create a Site Colection (Based on the Developer Site Template)
$template = Get-SPWebTemplate "DEV#0";
$siteColl = "<WebApplication Url>/sites/mystcoll";
New-SPSite -Url $siteColl -OwnerAlias "domain\user" -Template $template -Verbose
### Export Deploy a .wsp file to another Server
NB: Just cd into the dir where you have all your .wsp files and execute the commands a s batch in
Elevated SharePoint Management Shell.
$dir = "C:\COLLECTIONS\Deployment";
$list = Get-ChildItem $dir | where {$_.extension -eq ".wsp"};
foreach($my_file in Get-ChildItem $list){Add-SPSolution -LiteralPath $my_file.FullName};
foreach($my_file in Get-ChildItem $list){Install-SPSolution -Identity $my_file.Name -webapplication "http://s-hqs-spstagsvr/" -CompatibilityLevel {14,15} -GACDeployment -Confirm:$false};
@RodrigoAlbert
Copy link

Nice! Ty!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment