Failed to execute Troubleshoot-DatabaseSpace.ps1

Recently We have encountered issues with Exchange 2010 Troubleshoot-DatabaseSpace.ps1 after we upgraded exchange servers with powershell version 4.0

SCOM started throwing errors: Failed to execute Troubleshoot-DatabaseSpace.ps1.

This has happened because it needs PS version 2.0 for execution, We can’t remove PS 4.0 as our storage system software utilizes it.

SCOM MP was updated, powershell Fix was applied but still issue persists, It seems SCOM MP/PS Fix resolution works for 3.0 but not for 4.0.

Lifes-problems-GIF

We are still working with Microsoft for fixing this but till it is resolved we have used powershell to use Troulshoot-Databasespace.ps1 remotely as scheduled from admin server where we have Exchange tools installed & PS 2.0 is present.

Download & extract the script zip from below link:

https://gallery.technet.microsoft.com/scriptcenter/Failed-to-execute-dfcdaeec

Define the threshold that is required for alert mechanism:

$dbthreshold = “30” # means when 30% space is left in db drive

$logthreshold = “15” #means when 15% space is left in log drive

$path = “C:\Scripts\Trobleshoot-Database” # from where you are running the script

$limit = (Get-Date).AddDays(-30) # number of days you want to keep the log

$smtpserver = “smtpserver”

$from = “Monitoring@labtest.com”

$to = “Vsukhija@labtest.com”

$subj = “Database Script Execution Error”

$exscripts = “C:\Program Files\Microsoft\Exchange Server\V14\scripts\” #path for exchange script

We have scheduled it for every 15 mins, you can do according to your enviornmental needs..

Note:- Logs will be stored inside logs folder.

As soon as threshold is reached or script fails to execute, you will received alert on the defined email address..

###################################################################### 
#        Author: Vikas Sukhija  
#        Reviewer:     
#        Date: 01/06/2016 
#        Description: Using Troubleshoot-Databasespace.ps1 to  
#        generate email alerts to exchange Team( good for Non Scom 
#               Enviornemnt) 
###################################################################### 
######################ADD Exchange Shell############################## 
 
If ((Get-PSSnapin | where {$_.Name -match "Microsoft.Exchange.Management.PowerShell.E2010"}) -eq $null) 
{ 
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 
} 
 
#############Logs & Variables##################### 
 
$dbthreshold = "30" 
$logthreshold = "15" 
 
$date1 = get-date -format d 
$date1 = $date1.ToString().Replace("/","-") 
 
$time = get-date -format t 
$time = $time.ToString().Replace(":""-"$time = $time.ToString().Replace(" """) 
 
 
$path = "C:\Scripts\Trobleshoot-Database" 
$limit = (Get-Date).AddDays(-30) 
 
$logs = "C:\Scripts\Trobleshoot-Database\logs" + "\" + "Processed_DB_" + $date1 + "_" + $time + "_.log" 
 
$smtpserver = "smtpserver" 
$from = "Monitoring@labtest.com" 
$to = "Vsukhija@labtest.com" 
$subj = "Database Script Execution Error" 
$exscripts = "C:\Program Files\Microsoft\Exchange Server\V14\scripts\" 
 
########Function for error email###### 
 
Function erremail($smtpserver,$from,$To,$subj) { 
 
if ($error -ne $null) 
      { 
#SMTP Relay address 
$msg = new-object Net.Mail.MailMessage 
$smtp = new-object Net.Mail.SmtpClient($smtpServer) 
 
#Mail sender 
$msg.From = $from 
#mail recipient 
$msg.To.Add($to$msg.Subject = $subj 
$msg.Body = $error 
$smtp.Send($msg$error.clear() 
       } 
} 
############################################################ 
 
#######Change to Exscripts#################### 
 
cd $exscripts 
 
$collevents = @() 
 
$servers = Get-Exchangeserver | Where{$_.Name -like "*Dag*"} 
 
$servers | foreach-object{ 
 
$servername = $_.Name 
$servername 
 
$collevents = .\Troubleshoot-DatabaseSpace.ps1 -Server $servername -PercentEdbFreeSpaceThreshold $dbthreshold -PercentLogFreeSpaceThreshold $logthreshold -MonitoringContext 
 
$collevents | foreach-object { 
 
$eventid = $_.Eventid 
$eventtype = $_.Eventtype 
$eventmessage = $_.Eventmessage 
$date = get-date 
add-content $logs "$date $servername $eventid $eventmessage" 
 
if(($eventid -ne "5100"-and ($eventid -ne "5101"-and ($eventid -ne "5102")){ 
#SMTP Relay address 
$msg = new-object Net.Mail.MailMessage 
$smtp = new-object Net.Mail.SmtpClient($smtpServer) 
 
#Mail sender 
$msg.From = $from 
#mail recipient 
$msg.To.Add($to$msg.Subject = "Event Notification : OPEN CRITICAL : Datbase Disk Space $eventid" 
$msg.Body = $eventmessage 
$smtp.Send($msg) 
 
    } 
  } 
 
} 
#erremail $smtpserver $from $to $subj 
############################################################ 
########################Recycle logs ########################## 
 
Get-ChildItem -Path $path  | Where-Object {   
$_.CreationTime -lt $limit } | Remove-Item -recurse -Force

Regards

Sukhija Vikas

http://msexchange.me

Advertisements

2 thoughts on “Failed to execute Troubleshoot-DatabaseSpace.ps1

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