Skip to content

Commit 25244fd

Browse files
committed
Update script for enabling Change Analysis for a subscription
1 parent b7716b1 commit 25244fd

File tree

1 file changed

+22
-40
lines changed

1 file changed

+22
-40
lines changed

articles/azure-monitor/app/change-analysis.md

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -82,57 +82,39 @@ In Azure Monitor, Change Analysis is currently built into the self-service **Dia
8282

8383
### Enable Change Analysis at scale
8484

85-
If your subscription includes numerous web apps, enabling the service at the level of the web app would be inefficient. In this case, follow these alternative instructions.
85+
If your subscription includes numerous web apps, enabling the service at the level of the web app would be inefficient. Run the following script to enable all web apps in your subscription.
8686

87-
### Register the Change Analysis resource provider for your subscription
87+
Pre-requisites:
88+
* PowerShell Az Module. Follow instructions at [Install the Azure PowerShell module](https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-2.6.0)
8889

89-
1. Register the Change Analysis feature flag (preview). Because the feature flag is in preview, you need to register it to make it visible to your subscription:
90+
Run the following script:
9091

91-
1. Open [Azure Cloud Shell](https://azure.microsoft.com/features/cloud-shell/).
92+
```PowerShell
93+
# Log in to your Azure subscription
94+
Connect-AzAccount
9295
93-
![Screenshot of change Cloud Shell](./media/change-analysis/cloud-shell.png)
96+
# Get subscription Id
97+
$SubscriptionId = Read-Host -Prompt 'Input your subscription Id'
9498
95-
1. Change the shell type to **PowerShell**.
99+
# Make Feature Flag visible to the subscription
100+
Set-AzContext -SubscriptionId $SubscriptionId
96101
97-
![Screenshot of change Cloud Shell](./media/change-analysis/choose-powershell.png)
102+
# Register resource provider
103+
Register-AzResourceProvider -ProviderNamespace "Microsoft.ChangeAnalysis"
98104
99-
1. Run the following PowerShell command:
100105
101-
``` PowerShell
102-
Set-AzContext -Subscription <your_subscription_id> #set script execution context to the subscription you are trying to enable
103-
Get-AzureRmProviderFeature -ProviderNamespace "Microsoft.ChangeAnalysis" -ListAvailable #Check for feature flag availability
104-
Register-AzureRmProviderFeature -FeatureName PreviewAccess -ProviderNamespace Microsoft.ChangeAnalysis #Register feature flag
105-
```
106+
# Enable each web app
107+
$webapp_list = Get-AzWebApp | Where-Object {$_.kind -eq 'app'}
108+
foreach ($webapp in $webapp_list)
109+
{
110+
$tags = $webapp.Tags
111+
$tags[“hidden-related:diagnostics/changeAnalysisScanEnabled”]=$true
112+
Set-AzResource -ResourceId $webapp.Id -Tag $tags -Force
113+
}
106114
107-
1. Register the Change Analysis resource provider for the subscription.
115+
```
108116

109-
- Go to **Subscriptions**, and select the subscription you want to enable in the change service. Then select resource providers:
110117

111-
![Screenshot showing how to register the Change Analysis resource provider](./media/change-analysis/register-rp.png)
112-
113-
- Select **Microsoft.ChangeAnalysis**. Then at the top of the page, select **Register**.
114-
115-
- After the resource provider is enabled, you can set a hidden tag on the web app to detect changes at the level of deployment. To set a hidden tag, follow the instructions under **Unable to fetch Change Analysis information**.
116-
117-
- Alternatively, you can use a PowerShell script to register the resource provider:
118-
119-
```PowerShell
120-
Get-AzureRmResourceProvider -ListAvailable | Select-Object ProviderNamespace, RegistrationState #Check if RP is ready for registration
121-
122-
Register-AzureRmResourceProvider -ProviderNamespace "Microsoft.ChangeAnalysis" #Register the Change Analysis RP
123-
```
124-
125-
To use PowerShell to set a hidden tag on a web app, run the following command:
126-
127-
```powershell
128-
$webapp=Get-AzWebApp -Name <name_of_your_webapp>
129-
$tags = $webapp.Tags
130-
$tags[“hidden-related:diagnostics/changeAnalysisScanEnabled”]=$true
131-
Set-AzResource -ResourceId <your_webapp_resourceid> -Tag $tag
132-
```
133-
134-
> [!NOTE]
135-
> After you add the hidden tag, you might still need to wait up to 4 hours before you start seeing changes. Results are delayed because Change Analysis scans your web app only every 4 hours. The 4-hour schedule limits the scan's performance impact.
136118

137119
## Next steps
138120

0 commit comments

Comments
 (0)