Hi @sns,
- Yes, you need to delete unused web applications or site collections firstly in SharePoint Server and then delete corresponding databases from SQL Server.
If ((Get-PSSnapin | where {$_.Name -match "SharePoint.PowerShell"}) -eq $null)
{
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
Clear-Host
$webapps = Get-SPWebApplication
$Output = "C:\data.csv" #Output file
$SiteDataCollection = @() # Array to store data
foreach ($webapp in $webapps){
$webappurl = $webapp.URL;
$webappname=$webapp.DisplayName
$sites=get-spsite -limit all -WebApplication $webapp.URL
foreach ($site in $sites)
{
$ContentDB = Get-SPContentDatabase -site $site.url
$SiteData = New-Object PSObject
$SiteData | Add-Member -type NoteProperty -name "Site URL" -value $site.url
$SiteData | Add-Member -type NoteProperty -name "Database Name" -value $ContentDB.Name
$SiteData | Add-Member -type NoteProperty -name "Database Size" -value $($ContentDB.DiskSizeRequired /1024/1024)
$SiteDataCollection += $SiteData
}
}
$SiteDataCollection | Export-Csv -Path $Output -Force
Write-Host "Successfully Completed" -ForegroundColor DarkRed
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.