Skip to content

Instantly share code, notes, and snippets.

@ehrnst
Last active August 3, 2018 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehrnst/d314d415ade5cd072c9b11bb3affbc3c to your computer and use it in GitHub Desktop.
Save ehrnst/d314d415ade5cd072c9b11bb3affbc3c to your computer and use it in GitHub Desktop.
Send custom events to azure event grid from powershell
<#
.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