Skip to content

Instantly share code, notes, and snippets.

View ehrnst's full-sized avatar

Martin Ehrnst ehrnst

View GitHub Profile
@ehrnst
ehrnst / Get-PCAAppUserAuthenticationBearer.ps1
Last active December 23, 2022 01:12
Create a token to authenticate against microsoft partner center API as App + User
function Get-PCAppUserAuthenticationBearer {
<#
.SYNOPSIS
Function to retrieve App+User bearer token from Microsoft CSP API
.DESCRIPTION
This function connects to Azure AD to generate an oAuth token.
Aquired token is then used against the partner center REST API to generate a App+User jwt token. https://api.partnercenter.microsoft.com/generatetoken
You can read more about the authentication method here: https://msdn.microsoft.com/en-us/library/partnercenter/mt634709.aspx
.PARAMETER ClientID
@ehrnst
ehrnst / Get-AADAppoAuthToken.ps1
Created September 11, 2017 11:49
Generate azure AD application oAuth token
<#
.SYNOPSIS
Function to connect to the Microsoft login OAuth endpoint and return an OAuth token.
.DESCRIPTION
Generate Azure AD oauth token.
You can specify the resource you want in the paramenter. Default is management.core.windows.net
Parts of this function is created from these examples: https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-rest-api-walkthrough
.PARAMETER ClientID
@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 / 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 / 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 / reqCertFromTemplate.ps1
Last active July 12, 2023 13:55
Request and install a certificate from template using powershell
# Request the certificate throuh template called "WebServer"
Get-Certificate -Template "WebServer" -DnsName "computername.fqdn" -CertStoreLocation cert:\LocalMachine\My -SubjectName "CN=computerName.fqdn, C=CountryCode, L=MyCity, O=Organization OU=Department, S=State"
# After approval. Use request to download and install cert
$cert = (get-childItem -path cert:\LocalMachine\Request)
get-certificate -Request cert:\LocalMachine\Request\$cert
@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,