PowerShell SharePoint

SharePoint PowerShell 

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 ""} | 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 -identityhttp://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 –Identityhttp://MySiteCollection/ -Path C:\Backup\MysiteCollection.bak -Verbose

Note: Verbose use to see progress

7. Restore SharePoint Site Collection.

Command:  Restore-SPSite –Identityhttp://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 –WebApplicationhttp://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 –WebApplicationparameter. You can also use –Forceparameter 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 –Sitehttp://mysitecollection


17. Upgrade existing Sandboxed solution.

Command:  Update-SPUserSolution –Identity customsandboxsolution.wsp –Sitehttp://mysitecollection ToSolution customsandboxsolution2.wsp


18. Uninstall Sandboxed Solution.

Command:  Uninstall-SPUserSolution –Identity customsandboxsolution.wsp –Sitehttp://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

22. Get the servers in the farm - Online Status
Get-SPServer | Where-Object {($_.Role -ne 'Invalid') -and ($_.Status -eq 'Online')} | Select-Object -ExpandProperty Address




++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue #Load Module







##


## Common SharePoint configuration settings


##


#Retrieve Web Application information. The default depth of 2 does not return much detail--we recommend that you use a depth of 4 for this cmdlet.



Get-SPWebApplication | Export-Clixml .\WebAppFilename.xml -depth 4







#Retrieve custom layout information.



Get-SPWebApplication | Get-SPCustomLayoutsPage | Export-Clixml .\Get-SPCustomLayoutsPage.xml







#Determine how SharePoint designer access is configured.



Get-SPWebApplication | Get-SPDesignerSettings | Export-Clixml .\Get-SPDesignerSettings.xml







#Retrieve information about alternate access mapping



Get-SPAlternateURL | Export-Clixml .\Get-SPAlternateURL.xml







#Retrieve information about content databases



Get-SPContentDatabase | Export-Clixml .\Get-SPContentDatabase.xml







#Retrieve database properties for each database



Get-SPDatabase | Export-Clixml .\Get-SPDatabase.xml







#Retrieve information about all SharePoint Products installed in the farm, and the versions of all updates installed for each product.



Get-SPProduct | Export-Clixml .\Get-SPProduct.xml







#Retrieve farm information



Get-SPFarm | Export-Clixml .\Get-SPFarm.xml


Get-SPFarmConfig | Export-Clixml .\Get-SPFarmConfig.xml







#Retrieve information about the servers in the farm



Get-SPServer | Export-Clixml .\Get-SPServer.xml







#Retrieve information about installed features



Get-SPFeature | Export-Clixml .\Get-SPFeature.xml







#Retrieve information about globally-installed site templates



Get-SPWebTemplate | Export-Clixml .\Get-SPWebTemplate.xml







#Retrieve information about deployed solutions



Get-SPSolution | Export-Clixml .\Get-SPSolution.xml







#Retrieve information about sandboxed solutions deployed in a site collection



Get-SPSite | Get-SPUserSolution | Export-Clixml .\Get-SPUserSolution.xml







#Retrieve information about claims authentication



Get-SPTrustedIdentityTokenIssuer | Export-Clixml .\Get-SPTrustedIdentityTokenIssuer.xml


Get-SPTrustedServiceTokenIssuer | Export-Clixml .\Get-SPTrustedServiceTokenIssuer.xml


Get-SPTrustedRootAuthority | Export-Clixml .\Get-SPTrustedRootAuthority.xml







#Retrieve information about installed Help



Get-SPHelpCollection | Export-Clixml .\Get-SPHelpCollection.xml







#Retrieve information about the logging levels that have been set



Get-SPLogLevel | Export-Clixml .\Get-SPLogLevel.xml







#Retrieve information about the sites in the farm



Get-SPSite | Export-Clixml .\Get-SPSite.xml


Get-SPSiteAdministration | Export-Clixml .\Get-SPSiteAdministration.xml


Get-SPSiteSubscription | Export-Clixml .\Get-SPSiteSubscription.xml







#Retrieve ULS logging information



Get-SPDiagnosticConfig | Export-Clixml .\Get-SPDiagnosticConfig.xml


Get-SPDiagnosticsPerformanceCounter | Export-Clixml .\Get-SPDiagnosticsPerformanceCounter.xml


Get-SPDiagnosticsProvider | Export-Clixml .\Get-SPDiagnosticsProvider.xml







#Retrieve information about accounts registered in the configuration database



Get-SPManagedAccount | Export-Clixml .\Get-SPManagedAccount.xml


Get-SPProcessAccount | Export-Clixml .\Get-SPProcessAccount.xml


Get-SPShellAdmin | Export-Clixml .\Get-SPShellAdmin.xml







#Retrieve specific information about the certificate authority



Get-SPCertificateAuthority | Export-Clixml .\Get-SPCertificateAuthority.xml


Get-SPClaimProvider | Export-Clixml .\Get-SPClaimProvider.xml


Get-SPClaimProviderManager | Export-Clixml .\Get-SPClaimProviderManager.xml







#Retrieve information about content deployment jobs



Get-SPContentDeploymentJob | Export-Clixml .\Get-SPContentDeploymentJob.xml


Get-SPContentDeploymentPath | Export-Clixml .\Get-SPContentDeploymentPath.xml







#Retrieve information about the Mobile Messaging account.



Get-SPWebApplication | Get-SPMobileMessagingAccount | Export-Clixml .\Get-SPMobileMessagingAccount.xml







##


##Common service infrastructure settings


##


#Retrieve information about the service applications in the farm



Get-SPServiceApplication | Export-Clixml .\Get-SPServiceApplication.xml


Get-SPServiceApplicationPool | Export-Clixml .\Get-SPServiceApplicationPool.xml


Get-SPServiceApplicationProxy | Export-Clixml .\Get-SPServiceApplicationProxy.xml


Get-SPServiceApplicationProxyGroup | Export-Clixml .\Get-SPServiceApplicationProxyGroup.xml


Get-SPServiceApplication | Get-SPServiceApplicationEndpoint | Export-Clixml .\Get-SPServiceApplicationEndpoint.xml







#Retrieve information about the services running in the farm



Get-SPServiceInstance | Export-Clixml .\Get-SPServiceInstance.xml







#Retrieve information about InfoPath form services



Get-SPInfoPathFormsService | Export-Clixml .\Get-SPInfoPathFormsService.xml


Get-SPInfoPathFormTemplate | Export-Clixml .\Get-SPInfoPathFormTemplate.xml







###WARNING: The following cmdlet requires run as administrator rights.



Get-SPInfoPathUserAgent | Export-Clixml .\Get-SPInfoPathUserAgent.xml







#Retrieve information about common Web service settings



Get-SPServiceHostConfig | Export-Clixml .\Get-SPServiceHostConfig.xml







##


## Common service application settings


##


#Access Services


#Retrieve specific information for the Access Services service application



Get-SPAccessServiceApplication | Export-Clixml .\Get-SPAccessServiceApplication.xml







#Application Discovery and Load Balancer Service Application



Get-SPTopologyServiceApplication | Export-Clixml .\Get-SPTopologyServiceApplication.xml


Get-SPTopologyServiceApplicationProxy | Export-Clixml .\Get-SPTopologyServiceApplicationProxy.xml







#Business Data Connectivity Service


#Retrieve information about data connection files. ###WARNING: The following cmdlet requires run as administrator rights



Get-SPDataConnectionFile | Export-Clixml .\Get-SPDataConnectionFile.xml







###WARNING: The following cmdlet requires run as administrator rights



Get-SPDataConnectionFile | Get-SPDataConnectionFileDependent | Export-Clixml .\Get-SPDataConnectionFileDependent.xml







#Excel Services Application


#Note: An Excel service application must be provisioned for the following cmdlets to succeed.



Get-SPExcelServiceApplication | Get-SPExcelBlockedFileType | Export-Clixml .\Get-SPExcelBlockedFileType.xml


Get-SPExcelServiceApplication | Get-SPExcelDataConnectionLibrary | Export-Clixml .\Get-SPExcelDataConnectionLibrary.xml


Get-SPExcelServiceApplication | Get-SPExcelDataProvider | Export-Clixml .\Get-SPExcelDataProvider.xml


Get-SPExcelServiceApplication | Get-SPExcelFileLocation | Export-Clixml .\Get-SPExcelFileLocation.xml


Get-SPExcelServiceApplication | Export-Clixml .\Get-SPExcelServiceApplication.xml


Get-SPExcelServiceApplication | Get-SPExcelUserDefinedFunction | Export-Clixml .\Get-SPExcelUserDefinedFunction.xml


Get-SPWebApplication | Get-SPInfoPathWebServiceProxy | Export-Clixml .\Get-SPInfoPathWebServiceProxy.xml


Get-SPWebApplication | Get-SPManagedPath | Export-Clixml .\Get-SPManagedPath.xml







#Managed Metadata Service


#Note: A Managed Metadata service application must be provisioned for the following cmdlets to succeed.



Get-SPServiceApplication | ?{$_.TypeName -eq "Managed Metadata Service"} | %{$id = $_.Id;Get-SPMetadataServiceApplication -Id $_ | Export-Clixml .\Get-SPMetadataServiceApplication-$id.xml}


Get-SPServiceApplicationProxy | ?{$_.TypeName -eq "Managed Metadata Service Connection"} | %{$id = $_.Id;Get-SPMetadataServiceApplicationProxy -Id $_ | Export-Clixml .\Get-SPMetadataServiceApplicationProxy-$id.xml}


Get-SPSite | Get-SPTaxonomySession | Export-Clixml .\Get-SPTaxonomySession.xml







#PerformancePoint Service Application


#Note: A PerformancePoint service application must be provisioned for the following cmdlets to succeed.



Get-SPPerformancePointServiceApplication | Export-Clixml .\Get-SPPerformancePointServiceApplication.xml


Get-SPPerformancePointServiceApplication | Get-SPPerformancePointServiceApplicationTrustedLocation | Export-Clixml .\Get-SPPerformancePointServiceApplicationTrustedLocation.xml







#Search


#Retrieve search information


#Note: A Search service application must be provisioned for the following cmdlets to succeed.



Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchAdministrationComponent | Export-Clixml .\Get-SPEnterpriseSearchAdministrationComponent.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchCrawlContentSource | Export-Clixml .\Get-SPEnterpriseSearchCrawlContentSource.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchCrawlCustomConnector | Export-Clixml .\Get-SPEnterpriseSearchCrawlCustomConnector.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchCrawlDatabase | Export-Clixml .\Get-SPEnterpriseSearchCrawlDatabase.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchCrawlExtension | Export-Clixml .\Get-SPEnterpriseSearchCrawlExtension.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchCrawlMapping | Export-Clixml .\Get-SPEnterpriseSearchCrawlMapping.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchCrawlRule | Export-Clixml .\Get-SPEnterpriseSearchCrawlRule.xml


$searchApp = Get-SPEnterpriseSearchServiceApplication; Get-SPEnterpriseSearchExtendedClickThroughExtractorJobDefinition -SearchApplication $searchApp | Export-Clixml .\Get-SPEnterpriseSearchExtendedClickThroughExtractorJobDefinition.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchExtendedConnectorProperty | Export-Clixml .\Get-SPEnterpriseSearchExtendedConnectorProperty.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchExtendedQueryProperty | Export-Clixml .\Get-SPEnterpriseSearchExtendedQueryProperty.xml







###WARNING: The following command generates a 120MB file that records the out of the box settings###


#Note: The Get-SPEnterpriseSearchQueryAuthority and Get-SPEnterpriseSearchQueryDemoted cmdlets require the Owner and SearchApplication parameters#



Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchLanguageResourcePhrase | Export-Clixml .\Get-SPEnterpriseSearchLanguageResourcePhrase.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchMetadataCategory | Export-Clixml .\Get-SPEnterpriseSearchMetadataCategory.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchMetadataCrawledProperty | Export-Clixml .\Get-SPEnterpriseSearchMetadataCrawledProperty.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchMetadataManagedProperty | Export-Clixml .\Get-SPEnterpriseSearchMetadataManagedProperty.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchMetadataMapping | Export-Clixml .\Get-SPEnterpriseSearchMetadataMapping.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchQueryAuthority | Export-Clixml .\Get-SPEnterpriseSearchQueryAuthority.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchQueryDemoted | Export-Clixml .\Get-SPEnterpriseSearchQueryDemoted.xml


Get-SPEnterpriseSearchQueryAndSiteSettingsService | Export-Clixml .\Get-SPEnterpriseSearchQueryAndSiteSettingsService.xml


Get-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance | Export-Clixml .\Get-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance.xml


Get-SPEnterpriseSearchQueryAndSiteSettingsServiceProxy | Export-Clixml .\Get-SPEnterpriseSearchQueryAndSiteSettingsServiceProxy.xml


Get-SPEnterpriseSearchService | Export-Clixml .\Get-SPEnterpriseSearchService.xml


Get-SPEnterpriseSearchServiceInstance | Export-Clixml .\Get-SPEnterpriseSearchServiceInstance.xml







###WARNING: The following command generates a file per site collection###


#Note: The Get-SPEnterpriseSearchQuerySuggestionCandidates and Get-SPEnterpriseSearchRankingModel cmdlets require the Owner and SearchApplication parameters#



Get-SPSite | %{$id = $_.Id;Get-SPEnterpriseSearchQueryKeyword -Site $_ | Export-Clixml .\Get-SPEnterpriseSearchQueryKeyword-$id.xml}


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchQueryScope | Export-Clixml .\Get-SPEnterpriseSearchQueryScope.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchQueryScope | Get-SPEnterpriseSearchQueryScopeRule | Export-Clixml .\Get-SPEnterpriseSearchQueryScopeRule.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchQuerySuggestionCandidates | Export-Clixml .\Get-SPEnterpriseSearchQuerySuggestionCandidates.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchRankingModel | Export-Clixml .\Get-SPEnterpriseSearchRankingModel.xml


Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchSecurityTrimmer | Export-Clixml .\Get-SPEnterpriseSearchSecurityTrimmer.xml


Get-SPEnterpriseSearchServiceApplication | Export-Clixml .\Get-SPEnterpriseSearchServiceApplication.xml


Get-SPEnterpriseSearchServiceApplicationProxy | Export-Clixml .\Get-SPEnterpriseSearchServiceApplicationProxy.xml


Get-SPEnterpriseSearchSiteHitRule | Export-Clixml .\Get-SPEnterpriseSearchSiteHitRule.xml







#Security Token Service Application


#Retrieve information about the security token service used for incoming SOAP messages.



Get-SPSecurityTokenServiceConfig | Export-Clixml .\Get-SPSecurityTokenServiceConfig.xml







#State Service


#Retrieve information about the State Service.



Get-SPSessionStateService | Export-Clixml .\Get-SPSessionStateService.xml


Get-SPStateServiceApplication | Export-Clixml .\Get-SPStateServiceApplication.xml


Get-SPStateServiceApplicationProxy | Export-Clixml .\Get-SPStateServiceApplicationProxy.xml


Get-SPStateServiceDatabase | Export-Clixml .\Get-SPStateServiceDatabase.xml







#Usage and Health data collection


#Retrieve information about the Usage and Health Data Collection service application.



Get-SPUsageApplication | Export-Clixml .\Get-SPUsageApplication.xml


Get-SPUsageDefinition | Export-Clixml .\Get-SPUsageDefinition.xml


Get-SPUsageService | Export-Clixml .\Get-SPUsageService.xml







#Visio Service


#A Visio service application must be provisioned for the following cmdlets to succeed.



Get-SPVisioServiceApplication | Get-SPVisioExternalData | Export-Clixml .\Get-SPVisioExternalData.xml


Get-SPVisioServiceApplication | Get-SPVisioPerformance | Export-Clixml .\Get-SPVisioPerformance.xml


Get-SPVisioServiceApplication | Get-SPVisioSafeDataProvider | Export-Clixml .\Get-SPVisioSafeDataProvider.xml


Get-SPVisioServiceApplication | Export-Clixml .\Get-SPVisioServiceApplication.xml


Get-SPVisioServiceApplicationProxy | Export-Clixml .\Get-SPVisioServiceApplicationProxy.xml







#Web Analytics Service Application


#A Web Analytics service application must be provisioned for the following cmdlets to succeed.



Get-SPServiceApplication | ?{$_.TypeName -eq "Web Analytics Service Application"} | %{$id = $_.Id;Get-SPWebAnalyticsServiceApplication -Id $_ | Export-Clixml .\Get-SPWebAnalyticsServiceApplication-$id.xml}


Get-SPServiceApplicationProxy | ?{$_.TypeName -eq "Web Analytics Service Application Proxy"} | %{$id = $_.Id;Get-SPWebAnalyticsServiceApplicationProxy -Id $_ | Export-Clixml .\Get-SPWebAnalyticsServiceApplicationProxy-$id.xml}


Get-SPWebApplication | Get-SPWebApplicationHttpThrottlingMonitor | Export-Clixml .\Get-SPWebApplicationHttpThrottlingMonitor.xml


Get-SPWebPartPack | Export-Clixml .\Get-SPWebPartPack.xml







#Word Automation Services


###Note: These cmdlets are commented out because you are unlikely to want to run them. ###


#Get-SPSite | %{$web=Get-SPWeb $_.Url;$webid=$web.Id;$web | Get-SPUser | Export-Clixml .\Get-SPUser-$webid.xml}


# Get-SPSite | %{$web=Get-SPWeb $_.Url;$webid=$web.Id;$web | Export-Clixml .\Get-SPWeb-$webid.xml}




No comments:

Post a Comment