PowerShell is vital governance tools for SharePoint.
These are the some PowerShell commands Every Administrator Should know.
Add PowerShell to ISE.
Command: Add-PSSnapin Microsoft.SharePoint.PowerShell
1. 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
2. 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.
3. 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.
4. 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.
5.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.
6. Backup SharePoint Site Collection.
Command: Backup-SPSite –Identity http://MySiteCollection/ -Path C:\Backup\MysiteCollection.bak -Verbose
Note: Verbose use to see progress
7. Restore SharePoint Site Collection.
Command: Restore-SPSite –Identity http://MySiteCollection/ -Path C:\Backup\MysiteCollection.bak -Force -Verbose
8. 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
9. Restore SharePoint Farm
Command: Restore-SPFarm -Directory C:\FarmBackup -RestoreMethod overwrite
10. 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.
11. 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.
12. Uninstall SharePoint solution
Command: Uninstall-SPSolution –Identity customsolution.wsp –WebApplication http://webapplicationsite
13. Update SharePoint Solution
Command: Update-SPSolution –Identity customsolution.wsp –LiteralPath C:\customsolution.wsp –GACDeployment
14. Remove SharePoint Solution.
Command: Remove-SPSolution –Identity customsolution.wsp
15. Uploads a new sandboxed solution package to the solution gallery.
Command: Add-SPUserSolution –LiteralPath c:\customsandboxsolution.wsp –Site http://mysitecollection
16. Deploy Sandboxed solution.
Command: Install-SPUserSolution –Identity customsandboxsolution.wsp –Site http://mysitecollection
17. Upgrade existing Sandboxed solution.
Command: Update-SPUserSolution –Identity customsandboxsolution.wsp –Site http://mysitecollection ToSolution customsandboxsolution2.wsp
18. Uninstall Sandboxed Solution.
Command: Uninstall-SPUserSolution –Identity customsandboxsolution.wsp –Site http://mysitecollection
19. Remove Sandboxed solution package from the solution gallery.
Command: Remove-SPUserSolution –Identity customsandboxsolution.wsp –Site http://mysitecollection
20. Enable SharePoint Features
Command: Enable-SPFeature –Identity FeatureNameOrGUID –Url http://your site name
21. Disable SharePoint Features
Command: Disable-SPFeature –Identity FeatureNameOrGUID –Url http://your site name
by Amir Reza via Everyone's Blog Posts - SharePoint Community
No comments:
Post a Comment