- $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
- $LogFile = ".\UnusedContentDatabasesPatch-$LogTime.rtf"
- # Add SharePoint PowerShell Snapin
- if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
- Add-PSSnapin Microsoft.SharePoint.Powershell
- }
- $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
- Set-Location $scriptBase
- #Deleting any .rtf files in the scriptbase location
- $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf
- if($FindRTFFile)
- {
- foreach($file in $FindRTFFile)
- {
- remove-item $file
- }
- }
- start-transcript $logfile
- Function UnUsedContentDatabases()
- {
- $Output = $scriptBase + "\" + "UnUsedCDBs.csv";
- "UnUsedCDBs" | Out-File -Encoding Default -FilePath $Output;
- Write-host "Collecting information on used content databases" -fore yellow
- $webapplications = get-spwebapplication -IncludeCentralAdministration
- foreach($webapplication in $webapplications)
- {
- $CDBs = $webapplication.contentdatabases
- write-host "Total count of content databases associated with the webapp " $webapplication.url " is " $webapplication.contentdatabases.count -fore magenta
- foreach($CDB in $CDBs)
- {
- if($CDB.status -ne "Online")
- {
- write-host "The content database " $CDB.name " is offline and it is not in use" -for green
- $CDB.name | Out-File -Encoding Default -Append -FilePath $Output;
- }
- }
- }
- write-host "Output file generated and located at " $output -fore yellow
- }
- UnUsedContentDatabases
- stop-transcript
This program for Find Unused (Offline) Content Databases in SharePoint 2010.
