A discussion on setting up a trigger for an email notification for an RDS server with a powershell script was held. It was suggested to check the Windows event log and run a script when the trigger is fired. The email should only be sent once and not for all 3 servers in the folder. ControlUp Academy offers training for scripting.
Read the entire ‘Setting up an RDS Server Trigger and Script with ControlUp Academy’ thread below:
Hello,
I am trying to setup a trigger that will sends me an email when one of the 3 RDS servers (either one) in the folder will reach 10 or more sessions. Eventually this trigger will execute the powershell script.
I would like to get only one notification from the first server and not form the other 2. Anyone have an idea how to accomplish this?
How comfortable are you with scripting?
ControlUp evaluates triggers against individual objects. As in each machine is considered individually.
The basic idea is that you setup a trigger that runs a script. The script checks if the trigger has already fired for another machine. Typically via the Windows event log. Something like this:
“`$targetComputer = $args[0]
$eventLogName = "ControlUp Repeat Triggers"
$id = 1000 ## Needs to be unique between use cases!
$threshold = 1
$timeframe = 24##hours
try{
New-EventLog -LogName "Application" -Source $eventLogName -erroraction stop
}
catch
{
Ignore source is already registered error
}
check how many events have been logged
$filterhash = @{logname="application";providername=$eventLogName;id=$id;starttime=([datetime]::Now.AddHours(-$timeframe))}
[array]$number = Get-WinEvent -FilterHashtable $filterhash
if($number.count -le $threshold)
{
Write-Host "FOLLOW UP ACTION"
Send-MailMessage -To "[alerts@example.com](mailto:alerts@example.com)" -From "[controlup@example.com](mailto:controlup@example.com)" -Subject "example subject" -Body "example body"
} else
{
##write the event log
Write-EventLog -LogName Application -Source $eventLogName -EntryType Information -Message "Dummy" -EventId $id
}“`
Continue reading and comment on the thread ‘Setting up an RDS Server Trigger and Script with ControlUp Academy’. Not a member? Join Here!
Categories: All Archives, ControlUp Scripts & Triggers