Created
June 10, 2021 11:18
-
-
Save gislig/1aa3ef669eae4a99877b3e91e1bd1bde to your computer and use it in GitHub Desktop.
Push data from events on server to workplace group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Here is the API key from the custom integration | |
$apiKey = "THE CUSTOM INTEGRATION API KEY SHOULD BE SET HERE" | |
# Define the header with the API key with Bearer authorization | |
$headers = @{"Authorization" = "Bearer " + $apiKey} | |
# Define the path where you can search for groups | |
$apiGetPath = "https://graph.facebook.com/v2.11/community/groups" | |
# Find the id of the Monitoring Group | |
$GroupName = "MonitoringGroup" | |
$GroupID = ((Invoke-RestMethod -Method Get -Uri $apiGetPath -Headers $headers).data | ? { $_.Name -eq $GroupName }).id | |
# Getting event 4729, at least within the last 5 minutes, get the message | |
$Message = (Get-EventLog -LogName Security -After (Get-Date).AddMinutes(-5) -InstanceId 4728 -ErrorAction SilentlyContinue).Message | |
# Build the post method link with the groupid and the message | |
$apiPostPath = "https://graph.facebook.com/$GroupID/feed?message=$Message" | |
# Check if there is any data within the message; we don't want to send empty data. | |
if($Message){ | |
# Send the message | |
Invoke-RestMethod -Method Post -Uri $apiPostPath -Headers $headers | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment