Powershell - Delete / remove all site collection under a spesific managed path
-
29-09-2020 - |
Question
I've created a managed path for my team sites - called "workspaces". All team sites Have been created under the same managed path.
ex:
http://awesome.com/workspaces/teamsite1
http://awesome.com/workspaces/teamsite2
How can I list all team sites under a managed path?
What I want is to delete all site collection under a specific managed path. (remove site collection and DB-entry)
Solution
To list them, this actually gives you all sites under the path though:
Get-SPSite "http://awesome.com/workspaces*" -Limit ALL
To delete you should be able to use
Get-SPSite "http://awesome.com/workspaces*" -Limit ALL | Remove-SPSite -Confirm:$false
You can use
Remove-SPContentDatabase -Identity {GUID}
to remove a content database
OTHER TIPS
You can delete site collection using powershell by using following command
$tmpRoot = Get-SPWebApplication -Identity http://SP:2000
$tmpRootColl=$tmpRoot.Sites
#Enumerate through each site collection
for ($index=$tmpRootColl.Count-1 ; $index-ge 0 ; $index–-)
{
Remove-SPSite -Identity $tmpRootColl.Item($index) -GradualDelete -Confirm:$false
}
Get-SPDeletedSite | Remove-SPDeletedSite
Where $tmpRoot is Web Application and $tmpRootColl is collection of sites under web application
Find full code with explanation from this blog CodePlayAndLearn
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange