Following powershell reads the list of site collections from the file and deleted them:
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
function WriteLog
{
Param([string]$message, [string]$logFilePath)
Add-Content -Path $logFilePath -Value $message
}
$LogFile = "G:\DeletedSites.log"
$ListFile = "G:\List.csv"
$Sites = Import-CSV $ListFile
ForEach ($S in $Sites)
{
try
{
$URL = $S.URL
$Now = [System.DateTime]::Now
$MSG = $Now.ToString() + " | Deleting site: " + $URL
write-host $MSG
WriteLog $MSG $LogFile
Remove-SPSite -Identity $URL -GradualDelete -Confirm:$false
}
catch [system.exception]
{
$Now = [System.DateTime]::Now
$MSG = $Now.ToString() + "Exp: " + $_.Exception.Message
write-host -f red $MSG
WriteLog $MSG $LogFile
}
$Site = $Null
}
write-host "Done."
No comments:
Post a Comment