Skip to content

Instantly share code, notes, and snippets.

@ayesamson
Last active May 3, 2017 16:34
Show Gist options
  • Save ayesamson/a242d2f4a9ae42d06bc1297c8edff5a0 to your computer and use it in GitHub Desktop.
Save ayesamson/a242d2f4a9ae42d06bc1297c8edff5a0 to your computer and use it in GitHub Desktop.
Extract a portion of the WSFC Cluster Log using two points of time.
function Get-ClusterLogDetails {
[CmdletBinding()]
param (
[Parameter(Mandatory, ValueFromPipeline)]
[string]$servername,
[Parameter(Mandatory, ValueFromPipeline)]
[string]$starttime,
[Parameter(Mandatory, ValueFromPipeline)]
[string]$endtime
)
begin {
$filePath = "\\$($servername)\c$\Windows\Cluster\Reports\Cluster.log"
if(!(Test-Path $filePath)) {
Write-Output "Unable to connect to path [$($filePath)]"
Write-Output 'Terminating process.'
break;
}
}
process {
$startLine = Get-Content -Path $filePath | Select-String $starttime | select LineNumber -First 1
$endLine = Get-Content -Path $filePath | Select-String $endtime | select LineNumber -First 1
$finish = $endLine.LineNumber - $startLine.LineNumber
try {
# -join "`n" This needs to be in place in order for the following replace function properly convert line breaks to HTML
# -replace("`n","<br />") Added to preserve line breaks for HTML output
# -replace(" ERR "," <span style='background-color: #FFFF00'>ERR</span> ") Added to highlight keyword instances
[string]$details = @(Get-Content $filePath | Select-String $starttime -Context 0,$finish) -join "`n" -replace("`n","<br />") -replace(" ERR "," <span style='background-color: #FFFF00'>ERR</span> ")
}
catch {
Write-Output $_.Exception.Message
Write-Output 'Terminating process.'
break;
}
}
end {
# SEND NOTIFICATION
if ($details.Length -gt 0) {
# SMTP DETAILS
$from = '[email protected]'
$to = '[email protected]'
$sub = "$($servername) CLUSTER LOG REPORT - " + (get-date).ToString("yyyy-MM-dd")
$priority = 'High' #'High or Low'
$PSEmailServer = 'relay.domain.com'
$port = 25
try {
# SEND MESSAGE
Send-MailMessage -From $from -To $to -Body $details -Subject $sub -Priority $priority -Port $port -BodyAsHtml -ErrorAction Stop
}
catch {
Write-Output $_.Exception.Message
Write-Output 'Terminating process.'
break;
}
}
}
}
# USAGE EAXMPLE:
Get-ClusterLogDetails 'ServerName' '2017/05/02-02:30' '2017/05/02-02:34'
@ayesamson
Copy link
Author

ayesamson commented May 2, 2017

Much thanks to @bobfrankly, Devin Rich (@dr) & @DWSR from http://powershell.slack.com for the the help and suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment