-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-WECStatus.ps1
26 lines (26 loc) · 1.11 KB
/
Get-WECStatus.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$primaryEventCollector = "azvmwec02"
$upEvent = Get-WinEvent Microsoft-Windows-Forwarding/Operational -FilterXPath "*[System[(EventID=104)]]" -MaxEvents 1 | Where-Object {
$_.Message -match "http://$($primaryEventCollector)"
}
$downEvent = Get-WinEvent Microsoft-Windows-Forwarding/Operational -FilterXPath "*[System[(EventID=105)]]" -MaxEvents 1 | Where-Object {
$_.Message -match "http://$($primaryEventCollector)"
}
# Check to see if the last Service "down" event is newer than the last service "up" event.
if ($downEvent.TimeCreated -gt $upEvent.TimeCreated)
{
# Check to see if the other collector has been down for at least 5 minutes and that this collector service isn't already running.
if (($downEvent.TimeCreated -lt (Get-Date).AddMinutes(-5)) -and ((Get-Service Wecsvc).Status -ne "Running"))
{
Write-Host "Starting Local Service..."
Start-Service Wecsvc
}
}
else
{
# If the service "up" event is newer, stop the service if it's running
if ((Get-Service Wecsvc).Status -eq "Running")
{
Write-Host "Stopping local service..."
Stop-Service Wecsvc
}
}