- Using Azure CLI to add cert and hostname to web apps
- List Appsettings in every slot of every webapp and function app for a given sub
- List cosmos DBs in every resource group of a subscription and see their failover locations
- List cosmos DBs in every resource group of a subscription and find their current thoughput, etc.
- <19f1b72775e8bae45636ff1b0b529d57#Set-ApplicationInsightsRetention.ps1>
Last active
January 26, 2021 11:35
-
-
Save petevb/be0799e89d196a140c24c44b5e0b4dcd to your computer and use it in GitHub Desktop.
az cli samples #azcli #azure #bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://docs.microsoft.com/en-us/azure/azure-monitor/app/powershell#set-the-data-retention | |
Param( | |
[Parameter(Mandatory = $True)] | |
[string]$SubscriptionId, | |
[Parameter(Mandatory = $True)] | |
[string]$ResourceGroupName, | |
[Parameter(Mandatory = $True)] | |
[string]$Name, | |
[Parameter(Mandatory = $True)] | |
[string]$RetentionInDays | |
) | |
$ErrorActionPreference = 'Stop' | |
if (-not (Get-Module Az.Accounts)) { | |
Import-Module Az.Accounts | |
} | |
$azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile | |
if (-not $azProfile.Accounts.Count) { | |
Write-Error "Ensure you have logged in before calling this function." | |
} | |
$currentAzureContext = Get-AzContext | |
$profileClient = New-Object Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient($azProfile) | |
$token = $profileClient.AcquireAccessToken($currentAzureContext.Tenant.TenantId) | |
$UserToken = $token.AccessToken | |
$RequestUri = "https://management.azure.com/subscriptions/$($SubscriptionId)/resourceGroups/$($ResourceGroupName)/providers/Microsoft.Insights/components/$($Name)?api-version=2015-05-01" | |
$Headers = @{ | |
"Authorization" = "Bearer $UserToken" | |
"x-ms-client-tenant-id" = $currentAzureContext.Tenant.TenantId | |
} | |
## Get Component object via ARM | |
$GetResponse = Invoke-RestMethod -Method "GET" -Uri $RequestUri -Headers $Headers | |
## Update RetentionInDays property | |
if($($GetResponse.properties | Get-Member "RetentionInDays")) | |
{ | |
$GetResponse.properties.RetentionInDays = $RetentionInDays | |
} | |
else | |
{ | |
$GetResponse.properties | Add-Member -Type NoteProperty -Name "RetentionInDays" -Value $RetentionInDays | |
} | |
## Upsert Component object via ARM | |
$PutResponse = Invoke-RestMethod -Method "PUT" -Uri "$($RequestUri)" -Headers $Headers -Body $($GetResponse | ConvertTo-Json) -ContentType "application/json" | |
$PutResponse |
# app-insights is in preview so you may need:
# https://docs.microsoft.com/en-gb/cli/azure/ext/application-insights/monitor/app-insights?view=azure-cli-latest
az extension add -n application-insights
# tried these but the data they return doesn't include retentionInDays like powershell allows.
az monitor app-insights component show -g $rg
az monitor app-insights component show -a ttc-eun-pre -g ttc-pre -o json
az monitor app-insights component show -a ttc-eun-pre -g ttc-pre -o json
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment