Skip to content

Instantly share code, notes, and snippets.

View ehrnst's full-sized avatar

Martin Ehrnst ehrnst

View GitHub Profile
@ehrnst
ehrnst / GetResourceGroupHealth.ps1
Last active September 12, 2017 12:11
Get Azure resource health by resource group
#get the health of the whole resource group
# Add each health status to a hashtable before output a complete table with all resource groups and their resource health
$resourceGroupHealth = @{}
foreach ($ResourceGroup in $ResourceGroups) {
#Set resource group name and use it in our url
$health = Invoke-RestMethod -Uri "https://management.azure.com/subscriptions/$subscriptionID/resourceGroups/$ResourceGroup/Providers/Microsoft.ResourceHealth/availabilityStatuses?api-version=2015-01-01" -Method GET -Headers $authHeader
$currentHealth = @{}
$currentHealth = @{
@ehrnst
ehrnst / gist:49cd1d4cf40a21c6f0964c91a305efe0
Created October 1, 2017 19:59
Azure Funtion to start webasto heater with Altox WBUS
#Azure functions powershell http trigger
#Get input
$input = Get-Content $req -Raw | ConvertFrom-Json
[int]$tempLow = $input.tempLow
[int]$heatingMinutes = $input.heatingMinutes
function send-altoxCommand {
param (
[Parameter(Mandatory = $true)]
@ehrnst
ehrnst / Send-ALTOXCommand.ps1
Last active October 3, 2017 16:33
Altox WBUS API basic powershell
function send-altoxCommand {
param (
[Parameter(Mandatory = $true)]
$command,
[Parameter(Mandatory = $true)]
$pass,
[Parameter(Mandatory = $true)]
$email,
[Parameter(Mandatory = $true)]
$id
@ehrnst
ehrnst / Get-AzureMonitorAlertRules.ps1
Last active November 14, 2017 16:29
Azure monitor rest API powershell
$alertRules = Invoke-RestMethod -Method GET "https://management.azure.com/subscriptions/$SubscriptionId/resourcegroups/$ResourceGroupName/providers/microsoft.insights/alertrules?api-version=2016-03-01" -Headers $authHeader
$result = Get-AADAppoAuthToken -ClientID $AzureApplicationID -ClientSecret $ClientSecret -TenantId $TenantId
$AuthKey = "Bearer " + ($result.access_token)
$authHeader = @{
'Content-Type' = 'application/json'
'Accept' = 'application/json'
'Authorization' = $AuthKey
}
$Alert = $alertrules.id
(Invoke-RestMethod -Method GET "https://management.azure.com/$alert/incidents?api-version=$apiversion" -Headers $authHeader).value
@ehrnst
ehrnst / Get-AzureMonitorResourceGroupAlertRules.ps1
Last active November 14, 2017 16:44
This is a complete script authenticating using AAD application and get all alert rules from a resource group.
param (
# Your azure ad application ID
[Parameter(Mandatory)]
[String]
$AzureApplicationID,
# Azure AD application secret
[Parameter(Mandatory)]
[String]
$ClientSecret,
@ehrnst
ehrnst / New-AADAppDemo.ps1
Created April 9, 2018 11:51
Create Azure Active Directory application with powershell and set reader permission on subscription
<#
.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 / event-grid-function-test.ps1
Last active August 3, 2018 15:22
azure function return event grid validation event
# 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 August 3, 2018 15:32
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.