This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Connect to Azure specifying a tenant | |
| # If you want to connect to multiple tenants, you can connect multiple times. | |
| Connect-AzAccount -tenantId customer1.onmicrosoft.com | |
| # adding a new PowerShell Azure context | |
| # setting a friendly name to allow for easy switching. | |
| Set-AzContext -name "Subscription 1 in tenant 1" -SubscriptionId "31ffbc99-4cbf-43b2-8789-ba8d73171e70" -tenantid customer1.onmicrosoft.com | |
| Set-AzContext -name "Subscription 2 in tenant 1" -SubscriptionId "b5c85827-0afd-49a0-8923-8fe35cfa8dd0" -tenantid customer1.onmicrosoft.com |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", | |
| "contentVersion": "1.0.0.1", | |
| "parameters": { | |
| "resourceGroupName": { | |
| "type": "string", | |
| "metadata": { | |
| "description": "Specify the name of the resource group" | |
| } | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- | |
| IMPORTANT: | |
| - Policy elements can appear only within the <inbound>, <outbound>, <backend> section elements. | |
| - To apply a policy to the incoming request (before it is forwarded to the backend service), place a corresponding policy element within the <inbound> section element. | |
| - To apply a policy to the outgoing response (before it is sent back to the caller), place a corresponding policy element within the <outbound> section element. | |
| - To add a policy, place the cursor at the desired insertion point and select a policy from the sidebar. | |
| - To remove a policy, delete the corresponding policy statement from the policy document. | |
| - Position the <base> element within a section element to inherit all policies from the corresponding section element in the enclosing scope. | |
| - Remove the <base> element to prevent inheriting policies from the corresponding section element in the enclosing scope. | |
| - Policies are applied in the order of their appearance, from the top down. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # alert handeling | |
| # updating alert status | |
| # get alerts | |
| $alerts = Invoke-RestMethod -Method Get -Uri "https://management.azure.com/subscriptions/$subscriptionId/providers/Microsoft.AlertsManagement/alerts?api-version=2018-05-05" -Headers $headers | |
| # fore every alert I have. get it's ID and acknowledge it. | |
| # pay attention to the method is now POST (one can debate if this should be a PUT) | |
| foreach ($alert in $alerts.value) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| trigger: | |
| - master | |
| variables: | |
| # Agent VM image name | |
| vmImageName: 'windows-2019' | |
| # service connection (azure) | |
| azureServiceConnection: '{{ azServiceConnection }}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "$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", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "$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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |