If you schedule the following script with appropriate changes for Log file paths, emails, mailservers, will monitor SharePoint Logging Levels and sends an email if verbose is enabled in environment.
Set your default logging levels to monitor.
RunMonitorSPDiagLogging.bat
Set your default logging levels to monitor.
RunMonitorSPDiagLogging.bat
powershell.exe -command C:\PowerShell\MonitorSPDiagLogging\MonitorSPDiagLogging.ps1
MonitorSPDiagLogging.ps1
Set-ExecutionPolicy RemoteSigned
Set-ExecutionPolicy Unrestricted
#
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
#
$SetTraceSeverity="Unexpected"
$SetEventSeverity="Error"
#
$blnVerbose = "False"
#
$destfile = "C:\PowerShell\MonitorSPDiagLogging\MonitorSPDiagLoggingOut.log"
#
$SPDiagLog = Get-SPLogLevel | Select Area, Name, TraceSeverity, EventSeverity
#Get-SPLogLevel | Select Area, Name, TraceSeverity, DefaultTraceSeverity, EventSeverity, DefaultEventSeverity
foreach ( $obj in $SPDiagLog )
{
#$strLine=""
#$strLine = [string]::join($obj.Name, $obj.Area)
#$strLine = [string]$obj.Name + [string]$obj.Area
#Write-Host $obj.TraceSeverity $obj.DefaultTraceSeverity
#
if(($obj.TraceSeverity -eq "Verbose") -or ($obj.EventSeverity -eq "Verbose") -or ($obj.EventSeverity -eq "Information"))
{
if($obj.TraceSeverity -ne "VerboseEx")
{
#"verboseEx-False So Verbose=TRUE"
$blnVerbose = "True"
}
}
#
#$strLine5 = $strLine + $blnTrace + $blnEvent;
#$strLine5
}
#
if($blnVerbose -eq "True")
{
"Processing email... - one of service is in stopped mode.. "
$emailFrom = "SharePointSupport@unisys.com"
$emailTo = "User@Domain.com,User2@Domain"
#$emailTo = "User@Domain.com"
$subject = "Alert: Verify Diagnostic Logging Levels:" + $env:computername
$body = @"
Alert: Verify Diagnostic Logging Levels in $env:computername
-------------------------------------------------------------
Found verbose enabled for Trace or Verbose/Information Enabled for Event Logging
for some of objects in Diagnostic Logging.
Set logging to default using following command.
Use (PowerShell)
Set-SPLogLevel -TraceSeverity Unexpected -EventSeverity Error
Don't use (Stsadm)
stsadm -o setlogginglevel -tracelevel Unexpected -windowslogginglevel Error)
"@
$smtpServer = "mailrelay.na.uis.yourcorp.com"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
#$smtp.Dispose()
$strTimestamp = [string](Get-Date -format "yyyy-MM-dd_hh-mm-ss")
$strTimestamp
$strTimestamp + " : Email Processed" | Out-File "MonitorSPDiagLogging-ps1-Error.log" -append
#$host.SetShouldExit(5000)
}
No comments:
Post a Comment