I have a requirement which is with PowerShell script: when we deleting site collection with PowerShell before deleting we should have a backup copy(bak) in a specified location.


Remove-SPSite before this action we need to execute the backup-spsite action.

Please suggest me how to achieve the target.

2 Answers 2


Hello you can use below script.

Add-PsSnapin Microsoft.SharePoint.Powershell –ErrorAction SilentlyContinue
#Location of the Backup Folder  
#This will actually initiate the SPSite backup.
Backup-SPSite -Identity "http://portal/sites/production" -Path "C:\SPBackups\production.bak"

#This will actually initiate the SPSite Remove.
Remove-SPSite -Identity "http://portal/sites/production" -GradualDelete
#Catch error if  occured.
$ErrorMessage = $_.Exception.Message   
  • Let me try with above code and confirm? Sep 11, 2018 at 10:59
  • Working fine with the above code. Sep 19, 2018 at 9:32

enter image description here You can use this code for delete site collection and content db:

References: http://www.sharepointdiary.com/2015/06/delete-site-collection-using-powershell-in-sharepoint.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.