Useful PowerShell Command for SharePoint Administrator

  1. Add PowerShell to ISE.

    Command:

    Add-PSSnapin Microsoft.SharePoint.PowerShell

  2. Find an error from Correlation ID.

    Command:

    get-splogevent | ?{$_.Correlation -eq "<Correlation ID>"} | select Category, Level, EventID,Message | Format-List > C:\Correlationerror.log

    This Command list error message with Category, Level, EventID, Message in “C” drive by correlationerror name in notepad.

  3. Creating Site collection.

    Command:

    New-SPSite -Url "Your site url" -Name "MyTesting Site" -Template "STS#0" -OwnerAlias "Domain\owner" -Language 1033

    This example creates an English site collection owned by owner with Team Site Template. Lots of parameter can add as per requirement.

  4. Restore a deleted site collection.

    Command:

    Get-SPDeletedSite

    This command lists all deleted site with WebApplicationId, DatabaseID, SiteSubscriptionID, SiteID, Path, Scheme, Url, DeletionTime parameter.

    Restore-SPDeletedSite –Identity SiteID

    Find Respective SiteID of deleted site collection from Get-SPDeletedSite and replace it to Restore-SPDeletedSite –Identity SiteID.

  5. Export SharePoint List and library.

    Command:


    export-spweb -identity http://mytestsite -path c:\listName.cmp -itemurl /Lists/EmployeeDetails –includeusersecurity

    http://mytestsite -> site collection name.
    EmployeeDetails -> List name.
    c:\listName.cmp -> Save In C drive by listName with .cmp Extention.

  6. Import SharePoint List

    Command:

    Import-SPWeb -identity "http:// mytestsite " -path c:\listName.cmp –force

    "http:// mytestsite " is Site collection name where have to import.
    c:\listName.cmp is path from where we have to import listName.

  7. Backup SharePoint Site Collection.

    Command:

    Backup-SPSite –Identity http://MySiteCollection/ -Path C:\Backup\MysiteCollection.bak -Verbose

    Note: Verbose use to see progress.

  8. Restore SharePoint Site Collection.

    Command:

    Restore-SPSite –Identity http://MySiteCollection/ -Path C:\Backup\MysiteCollection.bak -Force -Verbose

  9. Backup SharePoint Farm

    Command:

    Backup-SPFarm -BackupMethod Full –Directory C:\FarmBackup\SPFarm

    Note: Above command Backups the entire database.

    Or

    Command:


    Backup-SPFarm -BackupMethod Differential –Directory C:\FarmBackup\SPFarm

    Note: Backs up only the changes made to the database since the last full backup. The differential backup method cannot be used to back up Index databases or Document Libraries. The Full backup method must be used to back up these resources.

  10. Restore SharePoint Farm

    Command:


    Restore-SPFarm -Directory C:\FarmBackup -RestoreMethod overwrite

  11. Add Solution -> Adds a SharePoint solution package to the farm.

    Command:

    Add-SPSolution C:\customsolution.wsp

    C is directory and customsolution.wsp is solution name.

  12. Install SharePoint Solution -> Deploy the SharePoint Solution in the Farm.

    Command:

    Install-SPSolution –Identity customsolution.wsp –WebApplication http://webapplicationsite–GACDeployment

    Note: If you are using the GAC or Code Access Security, Specify either –GACDeployment or –CASPolicies.

    –WebApplication parameter applies for particular web application.

    If have to apply for all web application use –AllWebApplications (Hope manifest allow this) Or don’t add –WebApplication parameter. You can also use –Force parameter to force the deployment.

  13. Uninstall SharePoint solution

    Command:

    Uninstall-SPSolution –Identity customsolution.wsp –WebApplication http://webapplicationsite

  14. Update SharePoint Solution

    Command:

    Update-SPSolution –Identity customsolution.wsp –LiteralPath C:\customsolution.wsp –GACDeployment

  15. Remove SharePoint Solution.

    Command:

    Remove-SPSolution –Identity customsolution.wsp

  16. Uploads a new sandboxed solution package to the solution gallery.

    Command:

    Add-SPUserSolution –LiteralPath c:\customsandboxsolution.wsp –Sitehttp://mysitecollection

  17. Deploy Sandboxed solution.

    Command:

    Install-SPUserSolution –Identity customsandboxsolution.wsp –Site http://mysitecollection

  18. Upgrade existing Sandboxed solution.

    Command:

    Update-SPUserSolution –Identity customsandboxsolution.wsp –Site http://mysitecollectionToSolution customsandboxsolution2.wsp

  19. Uninstall Sandboxed Solution.

    Command:

    Uninstall-SPUserSolution –Identity customsandboxsolution.wsp –Sitehttp://mysitecollection

  20. Remove Sandboxed solution package from the solution gallery.

    Command:

    Remove-SPUserSolution –Identity customsandboxsolution.wsp –Site http://mysitecollection

  21. Enable SharePoint Features

    Command:

    Enable-SPFeature –Identity FeatureNameOrGUID –Url http://your site name

  22. Disable SharePoint Features

    Command:

    Disable-SPFeature –Identity FeatureNameOrGUID –Url http://your site name
Ebook Download
View all
Learn
View all