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.
Prerequisites
Section titled “Prerequisites”pwsh --versionaz --version
# Log in and select the target subscriptionaz loginaz account set --subscription "<subscription-id>"
# Confirm the correct subscription is activeaz account show --query "{Name:name, Id:id}" -o tableYou need Owner or Resource Policy Contributor role on the subscription to create and delete policy assignments.
Running the Scripts
Section titled “Running the Scripts”Scripts are located in the scripts/ folder of this repository.
Run from the repository root:
pwsh -File scripts/<script-name>.ps1 -Subscription "<subscription-name-or-id>"Or navigate to the folder first:
cd scriptspwsh -File ./Setup-GovernancePolicies.ps1 -Subscription "<subscription-name-or-id>"Script Reference
Section titled “Script Reference”1. Setup-GovernancePolicies.ps1
Section titled “1. Setup-GovernancePolicies.ps1”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.
Setup Parameters
Section titled “Setup Parameters”| Parameter | Required | Description |
|---|---|---|
-Subscription | Yes | Azure subscription name or ID |
-WhatIf | No | Preview assignments without creating them |
-Verbose | No | Show detailed progress per assignment |
Setup Usage
Section titled “Setup Usage”# Preview first (always recommended)pwsh -File scripts/Setup-GovernancePolicies.ps1 \ -Subscription "<subscription-name-or-id>" \ -WhatIf
# Deploy policiespwsh -File scripts/Setup-GovernancePolicies.ps1 \ -Subscription "<subscription-name-or-id>"
# Deploy with verbose outputpwsh -File scripts/Setup-GovernancePolicies.ps1 \ -Subscription "<subscription-name-or-id>" \ -VerbosePolicies Deployed
Section titled “Policies Deployed”| Assignment Name | Policy | Effect | Constraint |
|---|---|---|---|
microhack-allowed-locations | Allowed locations | Deny | swedencentral, germanywestcentral, global only |
microhack-require-environment-tag | Require tag: Environment | Deny | All resources must have an Environment tag |
microhack-require-project-tag | Require tag: Project | Deny | All resources must have a Project tag |
microhack-sql-aad-only-auth | SQL Azure AD-only auth | Deny | No SQL password authentication |
microhack-storage-https-only | Storage HTTPS only | Deny | supportsHttpsTrafficOnly: true |
microhack-storage-min-tls | Storage min TLS 1.2 | Deny | minimumTlsVersion: 'TLS1_2' |
microhack-storage-no-public-blob | Storage no public blob | Deny | allowBlobPublicAccess: false |
microhack-appservice-https | App Service HTTPS only | Deny | httpsOnly: true |
Setup Output
Section titled “Setup Output”Subscription : my-subscription-nameSubscriptionId : 00000000-0000-0000-0000-000000000000Created : 8Skipped : 0Failed : 0TotalPolicies : 82. Get-GovernanceStatus.ps1
Section titled “2. Get-GovernanceStatus.ps1”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.
Status Parameters
Section titled “Status Parameters”| Parameter | Required | Description |
|---|---|---|
-Subscription | Yes | Azure subscription name or ID |
-MicrohackOnly | No | Filter to microhack-* assignments only |
-Verbose | No | Show detailed progress |
Status Usage
Section titled “Status Usage”# Check all policy assignments on the subscriptionpwsh -File scripts/Get-GovernanceStatus.ps1 \ -Subscription "<subscription-name-or-id>"
# Check only microhack policiespwsh -File scripts/Get-GovernanceStatus.ps1 \ -Subscription "<subscription-name-or-id>" \ -MicrohackOnlyStatus Output
Section titled “Status Output”Name DisplayName EnforcementMode State Compliant NonCompliant---- ----------- --------------- ----- --------- ------------microhack-al... Microhack: Allowed locations Default Compliant 12 0microhack-re... Microhack: Require Environment tag Default NonCompliant 8 4...3. Remove-GovernancePolicies.ps1
Section titled “3. Remove-GovernancePolicies.ps1”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.
Removal Parameters
Section titled “Removal Parameters”| Parameter | Required | Description |
|---|---|---|
-Subscription | Yes | Azure subscription name or ID |
-WhatIf | No | Preview removals without deleting anything |
-Verbose | No | Show detailed progress per assignment |
Removal Usage
Section titled “Removal Usage”# Preview what will be removedpwsh -File scripts/Remove-GovernancePolicies.ps1 \ -Subscription "<subscription-name-or-id>" \ -WhatIf
# Remove all microhack policiespwsh -File scripts/Remove-GovernancePolicies.ps1 \ -Subscription "<subscription-name-or-id>"Removal Output
Section titled “Removal Output”Subscription : my-subscription-nameSubscriptionId : 00000000-0000-0000-0000-000000000000Removed : 8Failed : 0TotalFound : 8Recommended Event Sequence
Section titled “Recommended Event Sequence”SUB="<your-subscription-name-or-id>"
# 1. Before the event — deploy governancepwsh -File scripts/Setup-GovernancePolicies.ps1 -Subscription $SUB -WhatIfpwsh -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 governancepwsh -File scripts/Remove-GovernancePolicies.ps1 -Subscription $SUB -WhatIfpwsh -File scripts/Remove-GovernancePolicies.ps1 -Subscription $SUBTroubleshooting
Section titled “Troubleshooting”| Symptom | Cause | Solution |
|---|---|---|
command not found: pwsh | PowerShell not installed | Run which pwsh; it should be pre-installed in devcontainer |
az: command not found | Azure CLI not installed | Azure CLI is pre-installed; try az login |
AuthorizationFailed | Insufficient role | Ensure Owner or Resource Policy Contributor on sub |
| Assignment creation fails silently | Policy definition ID changed | Check definition IDs via az policy definition list |
| Policy not blocking deployments | Propagation delay | Wait 5–15 minutes after Setup-GovernancePolicies.ps1 |
State: Unknown in status output | Compliance data not yet collected | Wait a few minutes and re-run Get-GovernanceStatus.ps1 |
| Assignments remain after cleanup | Failed count > 0 in Remove output | Re-run Remove-GovernancePolicies.ps1; check RBAC |