Thursday, October 30, 2014

Delete All Site collections [/sites] from web application using powershell

1. The Get-SPDeletedSite cmdlet lists all the deleted site collections.

2. Restore a deleted site collection.

Get-SPDeletedSite | where{$_.SiteId -eq "4563-6b2e-473b-b6c3-e0967996aa7d"} | Restore-SPDeletedSite

3. Use the Remove-SPDeletedSite to permanently remove the deleted site collection.

4. Just permanent site collection delete , won't be available to restore in Recycle bin[careful as always]

Remove-SPSite "http://sharepoint.com/sites/test"

5.  NO permanent site collection delete , still available for restore in Content database Recycle bin.

Remove-SPSite -Identity "http://sharepoint.com/sites/test1" -GradualDelete

Note: Use the (2) command to restore the site collection.

Now, let me try for my actual need :

6.  Get the all site collections under the web application

Get-SPSite "http://sharepoint.com" -Limit ALL

Now, we try find the site collections under specific root ex: http://sharepoint.com/sites/ or  http://sharepoint.com/personal/

Get-SPSite http://sharepoint.com/personal* -Limit ALL

Now , we will remove all the site collections under the /personal/ root folder

a)  Permanent delete , won't be available to restore in recycle bin  or content database

Get-SPSite "http://sharepoint.com/personal*" -Limit ALL | Remove-SPSite -Confirm:$false 

b) No permanant delete, will prompt for each site , still available for restore in recycle bin

Get-SPSite "http://sharepoint.com/personal*" -Limit ALL | Remove-SPSite -GradualDelete


This is solve the my need , to delete site collections under /personal/ root level in Sharepoint portal.