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
ehrnst / auhtenticateandquery.ps1
Created Mar 28, 2019
Azure AD authentication against azure functions using a custom app.
View auhtenticateandquery.ps1
# getting a token from login.microsoft.com
# scope here is my custom app ID which has a custom application role defined.
$tenantID = "tenant.onmicrosoft.com"
$myCustomAPPID = "customAppWithID/.default"
$ClientID = 'your client id'
$ClientKey = 'your client key'
$params = @{
scope = $myCustomAPPID;
grant_type = 'client_credentials';
client_id = $ClientId;
@ehrnst
ehrnst / azuredeploy.json
Created Mar 8, 2019
inline nesting test Azure template
View azuredeploy.json
{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.1",
"parameters": {
"rgName": {
"type": "string",
"defaultValue": "ehrnst-demo-function-rg"
},
"rgLocation": {
"type": "string",
@ehrnst
ehrnst / azuredeploy.json
Created Feb 15, 2019
101-webapp-basic-windows/azuredeploy.json
View azuredeploy.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"webAppName": {
"type": "string",
"metadata": {
"description": "Base name of the resource such as web app name and app service plan "
},
"minLength": 2
@ehrnst
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 = "https://login.windows.net/$partnerTenant/oauth2/token"
$params = @{
resource = "https://api.partnercenter.microsoft.com";
grant_type = "refresh_token";
@ehrnst
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 https://docs.microsoft.com/en-us/azure/event-grid/security-authentication
# check event type and return a Json object with the correct validation response
if ($requestBody.eventType -eq "Microsoft.EventGrid.SubscriptionValidationEvent") {
$code = $requestBody.data.validationCode
$content = @{ validationResponse = $code }
$message = convertto-json -compress -InputObject ([ordered]@{
body = $content
@ehrnst
ehrnst / postEventGridDemo1.ps1
Last active Aug 3, 2018
Send custom events to azure event grid from powershell
View postEventGridDemo1.ps1
<#
.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.
@ehrnst
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
<#
.SYNOPSIS
Creates an azure ad application and sets reader permissions on subscription
.NOTES
Script is provided as an example, it has no error handeling and is not production ready. App name and permissions is hard coded.
#>
param(
[Parameter(Mandatory)]
@ehrnst
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
[Parameter(Mandatory)]
[String]
$AzureApplicationID,
# Azure AD application secret
[Parameter(Mandatory)]
[String]
$ClientSecret,
View Get-AzureMonitorAlertRulesIncidents.ps1
$Alert = $alertrules.id
(Invoke-RestMethod -Method GET "https://management.azure.com/$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.