TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
PowerShell : Delete All Site Collection Present Under Web Application
Ketak Bhalsing
May 20
2016
Code
1.6
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
#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 -Global
PowerShell
SharePoint
Site Collection