Skip to content

Governance Scripts

Three PowerShell scripts manage the Azure Policy lifecycle for the microhack event. All require the Azure CLI (az) and PowerShell 7+ (pwsh), both pre-installed in the dev container.


Terminal window
pwsh --version
az --version
# Log in and select the target subscription
az login
az account set --subscription "<subscription-id>"
# Confirm the correct subscription is active
az account show --query "{Name:name, Id:id}" -o table

You need Owner or Resource Policy Contributor role on the subscription to create and delete policy assignments.


Scripts are located in the scripts/ folder of this repository.

Run from the repository root:

Terminal window
pwsh -File scripts/<script-name>.ps1 -Subscription "<subscription-name-or-id>"

Or navigate to the folder first:

Terminal window
cd scripts
pwsh -File ./Setup-GovernancePolicies.ps1 -Subscription "<subscription-name-or-id>"

View source on GitHub

When to use: Before the event starts, to deploy governance constraints that teams must work around.

Deploys eight Deny-effect policy assignments at the subscription scope. Assignments use the microhack- prefix and are idempotent — existing assignments are skipped automatically.

ParameterRequiredDescription
-SubscriptionYesAzure subscription name or ID
-WhatIfNoPreview assignments without creating them
-VerboseNoShow detailed progress per assignment
Terminal window
# Preview first (always recommended)
pwsh -File scripts/Setup-GovernancePolicies.ps1 \
-Subscription "<subscription-name-or-id>" \
-WhatIf
# Deploy policies
pwsh -File scripts/Setup-GovernancePolicies.ps1 \
-Subscription "<subscription-name-or-id>"
# Deploy with verbose output
pwsh -File scripts/Setup-GovernancePolicies.ps1 \
-Subscription "<subscription-name-or-id>" \
-Verbose
Assignment NamePolicyEffectConstraint
microhack-allowed-locationsAllowed locationsDenyswedencentral, germanywestcentral, global only
microhack-require-environment-tagRequire tag: EnvironmentDenyAll resources must have an Environment tag
microhack-require-project-tagRequire tag: ProjectDenyAll resources must have a Project tag
microhack-sql-aad-only-authSQL Azure AD-only authDenyNo SQL password authentication
microhack-storage-https-onlyStorage HTTPS onlyDenysupportsHttpsTrafficOnly: true
microhack-storage-min-tlsStorage min TLS 1.2DenyminimumTlsVersion: 'TLS1_2'
microhack-storage-no-public-blobStorage no public blobDenyallowBlobPublicAccess: false
microhack-appservice-httpsApp Service HTTPS onlyDenyhttpsOnly: true
Subscription : my-subscription-name
SubscriptionId : 00000000-0000-0000-0000-000000000000
Created : 8
Skipped : 0
Failed : 0
TotalPolicies : 8

View source on GitHub

When to use: Anytime — before, during, or after the event — to verify which policies are active and their compliance state.

Lists policy assignments on the subscription and reports compliance counts from Azure Policy state.

ParameterRequiredDescription
-SubscriptionYesAzure subscription name or ID
-MicrohackOnlyNoFilter to microhack-* assignments only
-VerboseNoShow detailed progress
Terminal window
# Check all policy assignments on the subscription
pwsh -File scripts/Get-GovernanceStatus.ps1 \
-Subscription "<subscription-name-or-id>"
# Check only microhack policies
pwsh -File scripts/Get-GovernanceStatus.ps1 \
-Subscription "<subscription-name-or-id>" \
-MicrohackOnly
Name DisplayName EnforcementMode State Compliant NonCompliant
---- ----------- --------------- ----- --------- ------------
microhack-al... Microhack: Allowed locations Default Compliant 12 0
microhack-re... Microhack: Require Environment tag Default NonCompliant 8 4
...

View source on GitHub

When to use: After the event ends, to restore the subscription to its pre-event state.

Finds and deletes all policy assignments with the microhack- prefix. Supports -WhatIf to preview removals before committing.

ParameterRequiredDescription
-SubscriptionYesAzure subscription name or ID
-WhatIfNoPreview removals without deleting anything
-VerboseNoShow detailed progress per assignment
Terminal window
# Preview what will be removed
pwsh -File scripts/Remove-GovernancePolicies.ps1 \
-Subscription "<subscription-name-or-id>" \
-WhatIf
# Remove all microhack policies
pwsh -File scripts/Remove-GovernancePolicies.ps1 \
-Subscription "<subscription-name-or-id>"
Subscription : my-subscription-name
SubscriptionId : 00000000-0000-0000-0000-000000000000
Removed : 8
Failed : 0
TotalFound : 8

Terminal window
SUB="<your-subscription-name-or-id>"
# 1. Before the event — deploy governance
pwsh -File scripts/Setup-GovernancePolicies.ps1 -Subscription $SUB -WhatIf
pwsh -File scripts/Setup-GovernancePolicies.ps1 -Subscription $SUB
# 2. Verify policies are active (run after 5–15 min)
pwsh -File scripts/Get-GovernanceStatus.ps1 -Subscription $SUB -MicrohackOnly
# 3. After the event — remove governance
pwsh -File scripts/Remove-GovernancePolicies.ps1 -Subscription $SUB -WhatIf
pwsh -File scripts/Remove-GovernancePolicies.ps1 -Subscription $SUB

SymptomCauseSolution
command not found: pwshPowerShell not installedRun which pwsh; it should be pre-installed in devcontainer
az: command not foundAzure CLI not installedAzure CLI is pre-installed; try az login
AuthorizationFailedInsufficient roleEnsure Owner or Resource Policy Contributor on sub
Assignment creation fails silentlyPolicy definition ID changedCheck definition IDs via az policy definition list
Policy not blocking deploymentsPropagation delayWait 5–15 minutes after Setup-GovernancePolicies.ps1
State: Unknown in status outputCompliance data not yet collectedWait a few minutes and re-run Get-GovernanceStatus.ps1
Assignments remain after cleanupFailed count > 0 in Remove outputRe-run Remove-GovernancePolicies.ps1; check RBAC