$spsite = New-SPSite -Url “http://Sp/sites/Sales” -ContentDatabase WSS_Content -OwnerAlias sp\administrator -Template “STS#0”
SharePoint feature
SharePoint onPrem 2013, 2016, 2019
Uninstall feature from SharePoint is one of the most important issue especially if you don’t know GUID for it. To uninstall the feature, you will need to get the feature first. Open SharePoint CMD as admin and use the following command
Get-SPFeature | where { $_.DisplayName.StartsWith("the feature name to be removed") }
Also, the feature can be found by GUID as in the following command
Get-SPFeature | where { $_.Id.ToString().StartsWith("Feature GUID") }
The complete command to uninstall the feature
Get-SPFeature | where { $_.DisplayName.StartsWith("feature name") } |
foreach { Uninstall-SPFeature $_.Id -confirm:0 -force }
This command is very helpful especially when the retract didn’t go well and the feature became orphaned feature .
Data Migration
Imagine the following scenario, in your company there is a SharePoint 2013 web application with huge document library and unique permission levels. The organization revamped this web application to SharePoint 2019 and now they need to migrate the documents along with the security.
Steps to follow for such scenario will be:
- Export the document library with the security by using the following CMDLET
- Export-SPWeb -Identity <Source Site URL> -Path “C:\BKP\docbak.cmp” [-ItemUrl <Library URL>] [-IncludeUserSecurity] [-IncludeVersions] [-NoFileCompression]
- Import the exported library by using the following CMDLET
- Import-SPWeb -Identity <Distination URL> -Path “C:\BKP\docbak.cmp” -Force -NoFileCompression -IncludeUserSecurity
Notice file compression is not used because if the document library is huge, the command could take days to run.
Sometimes the import command will fail. If SharePoint give reasons for failure and mostly it will be related to the security issues, you fix them and try again. If the failure continue to happen you can try the old cmd tool for SharePoint stsadm.exe
stsadm –o gl-importlist -url <Distination URL> -filename “C:\BKP\docbak.cmp” -includeusersecurity -nofilecompression
References:
Backup and Restore web applications
To backup SharePoint web applications :
- using PowerShell scripts, the following command shall be used
Backup-SPSite https://server_name/sites/site_name -Path C:\Backup\site_name.bak
2. using central administration:
To Restore SharePoint web applications:
- Central administration –> create new web application
- PowerShell script –> execute the following command
Restore-SPSite https://server_name/sites/site_name -Path C:\Backup\site_name.bak
Or the detailed command can be used in order to identify the database name and the server name
Restore-SPSite https://server_name/sites/site_name -Path C:\Backup\site_name.bak -Force -DatabaseServer SQLBE1 -DatabaseName SQLDB1
References:
Install and deploy custom solutions
Install SharePoint solution:
The cmdlet includes many parameters but the most commonly used is the following one:
Add-SPSolution -LiteralPath “physical path\solution name.wsp”
ex: Add-SPSolution -LiteralPath “c:\SolutionFolder\Solutionname.wsp”
Deploy SharePoint solution:
- deploy the solution globally into the farm:
- Install-SPSolution -Identity solutionname.wsp -GACDeployment
- deploy the solution to specific web application:
- Install-SPSolution -Identity solutionname.wsp -WebApplication “http://webappURL” -GACDeployment
- deploy the solution and identify the compatibility level (this is useful while upgrading the solution):
- Install-SPSolution -Identity solutionname.wsp -GACDeployment -CompatibilityLevel {14,15}
- Deploy the solution using the central administration:
- Login into central administration as the farm admin
- Navigate to system settings and choose farm solutions
- Check the solution list, the recently added one will have status “not deployed” choose and select the web application.
- Press deploy
That was a summary of the needed cmdlet to install and deploy SharePoint custom solutions