Delete site collection by reading csv File

Below script will read from csv file and delete the site collection.

Create CSV file with column name SiteUrl and add the list of sitecollection url.

Create file deleteSitecollection.ps1 and add the below code.

#Read the CSV file  

$CSVData = Import-CSV -path "D:\Data.csv"  

foreach($row in $CSVData)
{ 
write-host "Deleteing Site " + $row.SiteUrl  
remove-Spsite -identity $row.SiteUrl -confirm:$false  
Write-host ""
Write-host "Pausing for 600 seconds..."
Sleep 600
} 

It’s always recommended to put delay between deleting site collections. This is due to the fact that SQL server will not get overwhelmed by sudden deletion of large amount of data. So even though you can do it in one go, it is advised to wait for some time like at least 10 mins between each delete.delete.  we added sleep 600 to wait before next site collection delete.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s