TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Powwershell Script to Find Unused (Offline) Content Databases in SharePoint 2010
Karthik Muthu Karuppan
Feb 19
2015
Code
2.3
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
UnusedContentDatabas
$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
SharePoint
Find Unused Content Databases in SharePoint