Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Powwershell Script to Find Unused (Offline) Content Databases in SharePoint 2010
WhatsApp
Karthik Muthu Karuppan
Feb 19
2015
2.4
k
0
0
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
Find Unused Content Databases in SharePoint
SharePoint
Up Next
Powwershell Script to Find Unused (Offline) Content Databases in SharePoint 2010