How to monitor SharePoint 2010 databases with powershell and windows task scheduler
Hi,
In this post i will explain the way for how can we monitor SharePoint 2010 content databases through some simple tricks... First of all you need to create a list Central Administration Site as i created in this scenario named ("Content_db_Size") with following columns
Powershell Script:-
if(-not(Get-PSSnapin | where { $_.Name -eq
"Microsoft.SharePoint.PowerShell"}))
{
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
$adminwebapp = Get-spwebapplication -includecentraladministration | where {
$siteUrl = $adminwebapp
$listName = "Content_db_Size"
$spSite = new-object Microsoft.SharePoint.SPSite($siteUrl)
$spWeb = $spSite.OpenWeb()
$spList = $spWeb.Lists[$listName]
$webapps = Get-SPWebApplication
foreach($webapp in $webapps)
{
$ContentDatabases = $webapp.ContentDatabases
foreach($ContentDatabase in $ContentDatabases)
{
$ContentDatabaseSize = [Math]::Round
(($ContentDatabase.disksizerequired/1GB),2)
$addItem = $spList.Items.Add()
$addItem["Title"] = $webapp.DisplayName
$addItem["Content_db_Name"]= $contentdatabase.name
$addItem["DB_Size"] = $contentdatabasesize
$addItem.Update()
}
}
$spWeb.Dispose()
This script will Update the Content_db_Size list with the Web App Name, Database Name, Database Size.
To update this list on daily basis we need schedule this Powershell script with Windows server Task Scheduler
To Schedule:-
:-)
In this post i will explain the way for how can we monitor SharePoint 2010 content databases through some simple tricks... First of all you need to create a list Central Administration Site as i created in this scenario named ("Content_db_Size") with following columns
- Title,
- Content_db_Name
- Db_Size
Powershell Script:-
if(-not(Get-PSSnapin | where { $_.Name -eq
"Microsoft.SharePoint.PowerShell"}))
{
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
$adminwebapp = Get-spwebapplication -includecentraladministration | where {
$siteUrl = $adminwebapp
$listName = "Content_db_Size"
$spSite = new-object Microsoft.SharePoint.SPSite($siteUrl)
$spWeb = $spSite.OpenWeb()
$spList = $spWeb.Lists[$listName]
$webapps = Get-SPWebApplication
foreach($webapp in $webapps)
{
$ContentDatabases = $webapp.ContentDatabases
foreach($ContentDatabase in $ContentDatabases)
{
$ContentDatabaseSize = [Math]::Round
(($ContentDatabase.disksizerequired/1GB),2)
$addItem = $spList.Items.Add()
$addItem["Title"] = $webapp.DisplayName
$addItem["Content_db_Name"]= $contentdatabase.name
$addItem["DB_Size"] = $contentdatabasesize
$addItem.Update()
}
}
$spWeb.Dispose()
This script will Update the Content_db_Size list with the Web App Name, Database Name, Database Size.
To update this list on daily basis we need schedule this Powershell script with Windows server Task Scheduler
To Schedule:-
- Save the script (In my example: C:\ContentDatabaseSize.ps1)
- Start the Task scheduler: Start –> Run: taskschd.msc
- Create a new task and and make schedule accordingly.
:-)
Comments
Post a Comment