#check to see if the PowerShell Snapin is added
if ( (Get-PSSnapin -Name "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null )
{
Add-PsSnapin "Microsoft.SharePoint.PowerShell"
}
Start-SPAssignment -Global
function DeleteAllSiteCollections([string]$url)
{
try
{
$webApp = Get-SPWebApplication $url
foreach($siteCol in $webApp.Sites)
{
Remove-SPSite –Identity $siteCol.Url –GradualDelete –Confirm:$False
Write-Host "Successfully removed the site: " $siteCol.Url -ForegroundColor Green
}
}
catch [System.Exception]{ Write-Host $_.Exception.ToString()}
}
$webAppUrl = Read-Host "Enter the url of the Web Application"
DeleteAllSiteCollections $webAppUrl
Stop-SPAssignment -Globalthis PowerShell script to delete all the site collection present under Web Application.
