Sign in
Home
Library
Wiki
Learn
Gallery
Downloads
Support
Forums
Blogs
Resources For IT Professionals
United States (English)
Россия (Pусский)
中国(简体中文)
Brasil (Português)
Post an article
Translate this page
Powered by
Microsoft® Translator
Wikis - Page Details
First published by
Avni Bhatt
When:
18 Jun 2013 2:36 AM
Last revision by
Chen V
(MVP)
When:
4 Jul 2014 2:25 AM
Revisions:
7
Comments:
4
Options
Subscribe to Article (RSS)
Share this
Engage!
Wiki Ninjas Blog
(
Announcements
)
Wiki Ninjas on Twitter
TechNet Wiki Discussion Forum
Can You Improve This Article?
Positively!
Click Sign In to add the tip, solution, correction or comment that will help other users.
Report inappropriate content using
these instructions
.
Wiki
>
TechNet Articles
>
List Unused/Used/All Content Database through Powershell
List Unused/Used/All Content Database through Powershell
Article
History
List Unused/Used/All Content Database through Powershell
Reference :
http://gallery.technet.microsoft.com/office/List-Unused-Content-c078e894
clear
#Import Localized Data
#Import-LocalizedData -BindingVariable Message
#Add-PsSnapin Microsoft.SharePoint.PowerShell
#This function is used to get standard content database list for Get-OSCContentDatabase
function
Export-OSCContentDatabase
{
PARAM
(
$ContentDatabases
)
$ContentDatabases
|
Select-Object
-Property
`
@{
Name
=
"Url"
;
Expression
=
{
$_
.
WebApplication
.
Url
}
}
,
`
@{
Name
=
"ID"
;
Expression
=
{
$_
.
Id
}
}
,
`
@{
Name
=
"Name"
;
Expression
=
{
$_
.
Name
}
}
,
`
@{
Name
=
"WebApplication"
;
Expression
=
{
$_
.
WebApplication
}
}
,
`
@{
Name
=
"Server"
;
Expression
=
{
$_
.
Server
}
}
,
`
@{
Name
=
"CurrentSiteCount"
;
Expression
=
{
$_
.
CurrentSiteCount
}
}
,
`
@{
Name
=
"Status"
;
Expression
=
{
$_
.
Status
}
}
|
Sort-Object
-Property
Name
}
function
Get-OSCContentDatabase
{
[
CmdletBinding
(
DefaultParameterSetName
=
"UnUsedDatabase"
)
]
PARAM
(
[
Parameter
(
Mandatory
=
$false
,
Position
=
0
,
ParameterSetName
=
'UsedDatabase'
)
]
[switch]
$UsedDatabase
,
[
Parameter
(
Mandatory
=
$false
,
Position
=
0
,
ParameterSetName
=
'UnUsedDatabase'
)
]
[switch]
$UnUsedDatabase
)
[array]
$arrContentDB
=
@(
)
try
{
Get-SPWebApplication
-IncludeCentralAdministration
|
ForEach-Object
{
$arrContentDB
+=
$_
.
ContentDatabases
}
}
catch
[Exception]
{
#Catch and throw the terminating exception
throw
$Error
[
0
]
.
Exception
.
Message
}
#Check if content databases exist
if
(
$arrContentDB
.
Count
-eq
0
)
{
Write-Error
$Message
.
NoContentDB
return
$null
}
$scriptContentDBOutput
=
@(
)
$scriptContentDBOutput
+=
Export-OSCContentDatabase
$arrContentDB
#List the content databases which are in use currently
if
(
$UsedDatabase
)
{
Write-Host
$Message
.
UsedDatabase
$scriptContentDBOutput
=
$scriptContentDBOutput
|
Where-Object
{
$_
.
Status
-eq
"Online"
}
if
(
$scriptContentDBOutput
.
Count
-eq
0
)
{
Write-Host
$Message
.
ZeroUsedContentDB
return
$null
}
}
#List the content databases which are not in use currently
elseif
(
$UnUsedDatabase
)
{
Write-Host
$Message
.
UnUsedDatabase
$scriptContentDBOutput
=
$scriptContentDBOutput
|
Where-Object
{
$_
.
Status
-ne
"Online"
}
if
(
$scriptContentDBOutput
.
Count
-eq
0
)
{
Write-Host
$Message
.
ZeroUnusedContentDB
return
$null
}
}
#List all content databases
else
{
Write-Host
$Message
.
AllDatabase
if
(
$scriptContentDBOutput
.
Count
-eq
0
)
{
Write-Host
$Message
.
ZeroContentDB
return
$null
}
}
$scriptContentDBOutput
}
##Uncomment Following Line to List Out All Content Database
#Get-OSCContentDatabase
##Uncomment Following Line to List the content databases which are in use currently.
Get-OSCContentDatabase
-UsedDatabase
##Uncomment Following Line to List the content databases which are not in use currently.
#Get-OSCContentDatabase -UnUsedDatabase
Content Database
,
en-US
,
has code
,
PowerShell
,
SharePoint