Delete SharePoint SiteCollection via array of URLs

0

Microsoft PowerShell script to delete Microsoft SharePoint SiteCollections based on a given array of URLs.

# Array of SiteCollection
$urls = @(
    "https://sharepoint/1",
    "https://sharepoint/2"
)

# Load PowerShell Add-In
Add-PSSnapin Microsoft.SharePoint.PowerShell

# Iterate through array
ForEach ($url in $urls) {
    try {
        # Try to remove the SiteCollection
        Remove-SPSite $url
        Write-Output "SiteCollection $url deleted successfully." | Write-Host -ForegroundColor Cyan
    } catch {
        Write-Output "Something went wrong on SiteCollection $($url)." | Write-Host -ForegroundColor Red
        Write-Output "   $($_.Exception.Message)" | Write-Host -ForegroundColor Red
    }
}
Share.

About Author

Christian Unnerstall

Christian Unnerstall, founder of devshooin.com, enjoys designing and building things that look nice and work well, whether it's websites or services within the interwebs. Have questions - feel free to reach out to him. Enjoy

Leave a Reply