The EnableFoundryPurview.ps1 script is an interactive PowerShell tool that checks and manages Microsoft Purview compliance policies across your Azure subscriptions for Azure AI Foundry. It queries the Responsible AI (RAI) Policy API to determine whether Purview content-filtering is enabled on each subscription and provides options to enable or disable it in bulk or individually.
-
Authenticates to Azure using
Connect-AzAccount. -
Enumerates all subscriptions the signed-in user has access to.
-
Checks each subscription (in parallel) for an existing RAI Purview policy, reporting one of three statuses:
- ✅ Enabled — Purview content filters are active for both Prompt and Completion.
⚠️ Disabled — No Purview content filters are active.- ❌ Error — The subscription could not be queried (e.g., permission issues).
-
Presents an interactive menu with the following options:
Option Description 1 Enable Purview for a single disabled subscription 2 Disable Purview for a single enabled subscription 3 Enable Purview for all disabled subscriptions 4 Disable Purview for all enabled subscriptions Q Quit -
Refreshes and displays updated status after any change.
- Windows PowerShell 5.1 or PowerShell 7+ (cross-platform).
The script imports Az.Accounts for authentication and token acquisition. Install it if you haven't already:
Install-Module -Name Az.Accounts -Scope CurrentUser -ForceTip: If you already have the full Az module installed,
Az.Accountsis included.
You must have at least one Azure subscription. The script will enumerate every subscription visible to the authenticated identity.
The signed-in user must have one of the following roles assigned on each subscription they intend to manage:
The Owner role at the subscription scope is required to read/write RAI policies and enumerate subscriptions.
The Azure AI Account Owner role must be assigned on the Foundry resource or subscription scope. This role grants full access to manage projects and resources, and allows conditionally assigning the Azure AI User role to other principals.
For detailed permissions and guidance on assigning this role, see Role-based access control for Microsoft Foundry.
Open a PowerShell terminal (Windows Terminal, VS Code integrated terminal, or the standalone PowerShell console).
cd "<path-to-repo>\Foundry".\EnableFoundryPurview.ps1| Parameter | Description |
|---|---|
-Output <directory> |
Write detailed results to a timestamped text file in the specified directory. If omitted and the subscription count exceeds 50, a results file is automatically created in the current directory to avoid flooding the terminal. |
-FilterOpenAiSubscriptions |
Only process subscriptions that contain Azure OpenAI resources (Microsoft.CognitiveServices/accounts with kind eq 'OpenAI'). Subscriptions without OpenAI resources are excluded before any Purview checks. |
Examples:
# Default — check all subscriptions
.\EnableFoundryPurview.ps1
# Only subscriptions with OpenAI resources
.\EnableFoundryPurview.ps1 -FilterOpenAiSubscriptions
# Write results to a specific directory
.\EnableFoundryPurview.ps1 -Output "C:\Reports"
# Combine both
.\EnableFoundryPurview.ps1 -FilterOpenAiSubscriptions -Output "C:\Reports"A browser window (or device-code prompt) will appear for Azure sign-in via Connect-AzAccount. Sign in with an account that has the required permissions.
The script will list all subscriptions and their current Purview status:
=== Azure RAI Policy Purview Manager ===
Signing in... Done
Found 5 subscriptions
Checking subscriptions... Done
Contoso Dev [Enabled]
Contoso Prod [Disabled]
Sandbox [Error]
--- Summary ---
Enabled: 1 | Disabled: 1 | Errors: 1
--- Options ---
[1] Enable Purview for a subscription
[2] Disable Purview for a subscription
[3] Enable ALL disabled subscriptions
[4] Disable ALL enabled subscriptions
[Q] Quit
Choice:
Follow the prompts to enable/disable Purview as needed. After the operation completes, the script refreshes and displays the updated status.
| Symptom | Likely Cause | Resolution |
|---|---|---|
Import-Module Az.Accounts fails |
Module not installed | Run Install-Module Az.Accounts -Scope CurrentUser |
| Subscription shows [Error] | Insufficient permissions on that subscription | Verify the user has Owner on the subscription and Azure AI Account Owner on the Foundry resource |
| Enable/Disable fails with 403 Forbidden | Missing Owner or Azure AI Account Owner role | Assign Owner at the subscription scope and Azure AI Account Owner on the Foundry resource |
| No subscriptions found | Account has no subscription access | Confirm the signed-in account has Owner on at least one subscription |
| API | Version Used | Documentation |
|---|---|---|
| Azure Resource Manager — Subscriptions | 2025-04-01 |
List Subscriptions |
| Cognitive Services — RAI Policy | 2025-10-01-preview |
Cognitive Services REST API |
| Azure Resource Graph | 2021-03-01 |
Resource Graph REST API |