Skip to content

Instantly share code, notes, and snippets.

Martin Ehrnst ehrnst

Block or report user

Report or block ehrnst

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
ehrnst / auhtenticateandquery.ps1
Created Mar 28, 2019
Azure AD authentication against azure functions using a custom app.
View auhtenticateandquery.ps1
# getting a token from
# scope here is my custom app ID which has a custom application role defined.
$tenantID = ""
$myCustomAPPID = "customAppWithID/.default"
$ClientID = 'your client id'
$ClientKey = 'your client key'
$params = @{
scope = $myCustomAPPID;
grant_type = 'client_credentials';
client_id = $ClientId;
ehrnst / azuredeploy.json
Created Mar 8, 2019
inline nesting test Azure template
View azuredeploy.json
"$schema": "",
"contentVersion": "",
"parameters": {
"rgName": {
"type": "string",
"defaultValue": "ehrnst-demo-function-rg"
"rgLocation": {
"type": "string",
ehrnst / azuredeploy.json
Created Feb 15, 2019
View azuredeploy.json
"$schema": "",
"contentVersion": "",
"parameters": {
"webAppName": {
"type": "string",
"metadata": {
"description": "Base name of the resource such as web app name and app service plan "
"minLength": 2
ehrnst / Azure-graph-partnerCenter-examples.ps1
Last active Jan 20, 2019
CSP Secure app model with Powershell
View Azure-graph-partnerCenter-examples.ps1
# Connect to partner center via refresh token
# Considering the refresh token is stored securely. We will have to get a new access token.
$clientId = {multi tenant app id}
$secret = {multi tnant app secret}
$partnerAccessTokenUri = "$partnerTenant/oauth2/token"
$params = @{
resource = "";
grant_type = "refresh_token";
ehrnst / event-grid-function-test.ps1
Last active Aug 3, 2018
azure function return event grid validation event
View event-grid-function-test.ps1
# POST method: $req
$requestBody = Get-Content $req -Raw | ConvertFrom-Json
## validate event grid as described in
# check event type and return a Json object with the correct validation response
if ($requestBody.eventType -eq "Microsoft.EventGrid.SubscriptionValidationEvent") {
$code = $
$content = @{ validationResponse = $code }
$message = convertto-json -compress -InputObject ([ordered]@{
body = $content
ehrnst / postEventGridDemo1.ps1
Last active Aug 3, 2018
Send custom events to azure event grid from powershell
View postEventGridDemo1.ps1
Example code on how to post messages to a custom event grid topic
part of a blog article on
$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.
ehrnst / New-AADAppDemo.ps1
Created Apr 9, 2018
Create Azure Active Directory application with powershell and set reader permission on subscription
View New-AADAppDemo.ps1
Creates an azure ad application and sets reader permissions on subscription
Script is provided as an example, it has no error handeling and is not production ready. App name and permissions is hard coded.
ehrnst / Get-AzureMonitorResourceGroupAlertRules.ps1
Last active Nov 14, 2017
This is a complete script authenticating using AAD application and get all alert rules from a resource group.
View Get-AzureMonitorResourceGroupAlertRules.ps1
param (
# Your azure ad application ID
# Azure AD application secret
View Get-AzureMonitorAlertRulesIncidents.ps1
$Alert = $
(Invoke-RestMethod -Method GET "$alert/incidents?api-version=$apiversion" -Headers $authHeader).value
View AzureAuthHeader.ps1
$result = Get-AADAppoAuthToken -ClientID $AzureApplicationID -ClientSecret $ClientSecret -TenantId $TenantId
$AuthKey = "Bearer " + ($result.access_token)
$authHeader = @{
'Content-Type' = 'application/json'
'Accept' = 'application/json'
'Authorization' = $AuthKey
You can’t perform that action at this time.