Common PowerShell commands

Here are some commonly used PowerShell commands:

1. Add-SPSolution “<file location\Name.wsp>”

e.g. Add-SPSolution “c:\customsolution.wsp”

2. Install-SPSolution -Identity <Name.wsp> -WebApplication http://name -GACDeployment

e.g. Install-SPSolution -Identity customsolution.wsp -WebApplication http://sp10/sites/finance -GACDeployment

3. Uninstall-SPSolution -Identity <Name.wsp> -WebApplication http://name

e.g. Uninstall-SPSolution -Identity customsolution.wsp -WebApplication http://sp13/sites/hr

4. Remove-SPSolution -Identity <Name.wsp>

e.g. Remove-SPSolution -Identity customsolution.wsp

How to change a site collection’s URL

1. Backup the site collection using PowerShell or the menu option available in Central Admin.

2. To restore, use PowerShell. Here is an example:

Restore-SPSite -Identity http://thehub.harrogate.local/bussupport/procurement -Path c:\backup\SharePoint\[BackupFileName.bak] -DatabaseServer [DatabaseServerName] -DatabaseName [ContentDatabaseName] -Force

How to create a new site collection assigned to a new content database

$db=New-spcontentdatabase –name “Marketing_ContentDB01” –webapplication http://sp10; new-spsite –url http://sp10/sites/marketing -name “Marketing Site” –description “Welcome to the Marketing Site” –owneralias “contoso\driscollm” –contentdatabase $db –template “STS#0”