Home > PowerShell, SharePoint 2010, SharePoint 2010 Maintenance > SharePoint 2010 Maintenance Series: Check Disks using PowerShell

SharePoint 2010 Maintenance Series: Check Disks using PowerShell

If your IT enviornment is one of the lucky ones that have already implimented System Center Operations Manager (SCOM) then the easiness of monitoring and maintaing your SharePoint environments is simple.  If you are not one of the lucky ones you can impliment a series of PowerShell scripts to help you monitor your environment.  This blog posting will be the first of a series of scripts you can use to help monitor.

First in the series is a script that checks the local disk space on your front ends to make sure there is enough space available and sends out alerts and emails when avaiable space is running low.  Those that work with SharePoint know that IIS logs and ULS logs can quickly consume alot of space on your local drives.  If you have an extensive amount of drive space then this might not be a prolem, but if you don’t this can cause serious problems and space needs to be cleaned up before SharePoint decides to stop working.

Copy the below PowerShell scipt and paste into Notepad.  Change the values highlighted in “red” to reflect your SharePoing environment.  Save as check-disk.ps1 or anyname of your choosing.

Now you can add this script to a Task Scheduler to one of your servers in the fam as scheduled job.

Credit for this script goes to my co-worker Tony Brown who initially developed this handy script.

==================================================================

function test-disk {
param([string]$server)
trap{
“Failed.  Details: $($_.Exception)”
$emailFrom = emailFrom@email.com
$emailTo = emailTo@email.com
$subject = “PS Monitor – $svcname on $server is inaccessible”
$body = “$svcname on $server is inaccessible.  Details: $($_.Exception)”
$smtpServer = “Name of SMTP Server”
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
}

$disks = get-wmiobject -class win32_LogicalDisk -ComputerName $server

$disks | % {
if ($_.DriveType -eq 3 -and $_.FreeSpace -le 2000000000 – and $_.volumeName -ne “MSTDC” -and $_.VolumnName -ne “Quorum”) {
$free = $_.Freespace/1024/1024
$freepct = ($_.Freespace/$_.Size) * 100
$emailFrom = emailFrom@email.com
$emailTo = emailTo@email.com
if ($_.FreeSpace -le 100000000) {$subject = “SP2010 Monitor – $($_.Name) on $server is VERY LOW on disk space”} else {$subject = “PS Monitor – $($_.Name) on $server is low on disk space”}
$body = “$($_.Name) ($($_.VolumnName)) on $server has {0:N0} MBs available ({1:N1}% free)`n`nPlease remove extra files from temp directories and user profiles.  Try reducing logging or deleting old backups to prevent a disk outtage. `n`nSent from NAME OF Server, monitoring the SharePoint 2010 system. `nhttp://portal” -f $free, $freepct
$smtpServer = “Name of SMTP Server”
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
}

test-disk “Name of Server Front End 1”
test-disk “Name of Server Front End 2”
test-disk “Name of Central Admin Server”
test-disk “Name of Index Server”
test-disk “Name of Crawl Server”

====================================================================

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: