Thursday, October 2, 2014

Bulk Site Collection Deletion using PowerShell

Description:
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."

Knowledge Chat Bot (No Code)

Recently my customers was looking for a solution where on-field guys can search for answers related to their tasks and it was a perfect scen...