Skip to content

Instantly share code, notes, and snippets.

View krnese's full-sized avatar
💭
Living the dream

Kristian Nese krnese

💭
Living the dream
View GitHub Profile
{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"resources": [
{
"type": "Microsoft.Authorization/policyDefinitions",
"apiVersion": "2019-06-01",
"name": "keyvaultDiag",
"properties": {
@krnese
krnese / ARM template sample
Created May 24, 2020 11:17
Enable diagnostics of AAD to Log Analytics
{
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/tenantDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"logAnalyticsResourceId": {
"type": "string",
"metadata": {
"description": "Provide the resourceId to your Log Analytics workspace that will receive the AAD auding/sign-in logs."
}
}
{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"sharedServicesRgName": {
"type": "string",
"metadata": {
"description": "Provide name for the shared services resource group"
}
},
@krnese
krnese / gist:a1bb0679e9250ad2a3112e4a27498dde
Created April 14, 2020 15:22
ARM to trigger deployIfNotExist policies
{
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/tenantDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"policyDefinitionId": {
"type": "string"
},
"policyAssignmentId": {
"type": "string"
}
@krnese
krnese / mgPolicyOutput
Created April 7, 2020 11:06
policy resource deployment from mg
{
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters":{},
"resources":[],
"outputs": {
"policyDefinitionTemplate": {
"value": "[reference('/subscriptions/4d6a661f-2192-5ef8-a377-ae79beb54f3c/providers/Microsoft.Authorization/policyDefinitions/614c4ec0-be43-4dd5-bd50-b21e570c4abb', '2018-05-01').policyRule.then.details.deployment.properties.template]",
"type": "object"
},
@krnese
krnese / policyResourceDeployment
Last active April 7, 2020 09:57
deploy resources from policy assignment
{
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters":{},
"resources":[],
"outputs": {
"policyDefinitionTemplate": {
"value": "[reference('/subscriptions/4d6a661f-2192-5ef8-a377-ae79beb54f3c/providers/Microsoft.Authorization/policyDefinitions/09612efe-434f-4555-bd46-4ca7dcc4c709', '2018-05-01').policyRule.then.details.deployment.properties.template]",
"type": "object"
},
{
"properties": {
"displayName": "Deploys Activity Logs to Log Analytics",
"policyType": "Custom",
"mode": "All",
"description": "Ensures that Activity Log Diagnostics settings are set to push logs into Log Analytics",
"parameters": {
"logAnalytics": {
"type": "String",
"metadata": {
@krnese
krnese / deploy log analytics
Created April 3, 2020 12:51
policy log analytics
{
"properties": {
"displayName": "Deploy Azure Log Analytics if not exist on subscription",
"mode": "All",
"policyType": "Custom",
"parameters": {
"workspaceName": {
"type": "string",
"metadata": {
"description": "Provide suffix for Log Analytics workspace that will be created per subscription"
@krnese
krnese / Get-AzMgHiearchy
Created March 19, 2020 12:17
List Mg hiearchy
function Get-AzMgHierarchy {
[cmdletbinding()]
param (
[string]$mgGroupId
)
# Getting Azure connection context for the signed in user
$currentContext = Get-AzContext
# fetching new token
@krnese
krnese / PS Snippet
Created March 5, 2020 12:02
Read tenant level activity log
# Query Tenant Activity Log for the last 10 days
$GetDate = (Get-Date).AddDays((-10))
$dateFormatForQuery = $GetDate.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
# Getting Azure context for the API call
$currentContext = Get-AzContext
# fetching new token