Last active
August 3, 2018 15:32
-
-
Save ehrnst/d314d415ade5cd072c9b11bb3affbc3c to your computer and use it in GitHub Desktop.
Send custom events to azure event grid from powershell
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
<# | |
.Synopsis | |
Example code on how to post messages to a custom event grid topic | |
.Notes | |
part of a blog article on https://adatum.no | |
#> | |
$eventDate = get-date -Format s # get the date and time for the event. Has to be sortable for event grid to accept. Pass as a string | |
$eagSASkey = "HCDs7UFipbBXZ0OPc+mM=2" # access key. | |
$eventTopicURL = "https://adatumblogdemo.northeurope-1.eventgrid.azure.net/api/events" # Get this url from the azure portal | |
$eventID = Get-Random 99999 # generate a unique ID for the event | |
# raw json. Use Convertto-Json if you find that easier | |
$json = @" | |
[ | |
{ | |
"subject": "firstSubject", | |
"id": $eventID, | |
"eventType": "demo", | |
"eventTime": "$eventDate", | |
"data":{ | |
"name": "Donald" | |
}, | |
"dataVersion": 1 | |
} | |
] | |
"@ | |
# Make the noise | |
Invoke-RestMethod -Uri $eventTopicURL -Method POST -Body $json -Headers @{"aeg-sas-key" = $eagSASkey} -ContentType 'Application/json' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment