Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tcartwright/d2c9eb4ed072993d2062b02ffc42b3d2 to your computer and use it in GitHub Desktop.
Save tcartwright/d2c9eb4ed072993d2062b02ffc42b3d2 to your computer and use it in GitHub Desktop.
POWERSHELL: Turn off client ip masking for all application insights resources
Clear-Host
<###########################################################################
Author: Tim Cartwright
Purpose to turn off client ip masking for all application insights resources if masking is enabled
DisableIPMasking:
- true: disable masking client ips with 0.0.0.0 and show the real client ip
- false: masks all client ips with 0.0.0.0
###########################################################################>
if (-not (Get-AzContext)) {
Update-AzConfig -EnableLoginByWam $false
Connect-AzAccount
}
<#
IF YOU RECIEVE THIS ERROR, IT MEANS THAT THE WORKSPACE FOR THE RESOURCE IS MESSED UP. THERE SHOULD BE A WARNING AT THE TOP OF THE OVERVIEW ON THE RESOURCE:
--------------------------------------------------------------------------------------------------------------------------------------------------------------
New-AzApplicationInsights_CreateExpanded : Could not retrieve the Log Analytics workspace from ARM: /subscriptions/3f1b1b08-5eb5-4120-830c-de5b1d33f9a5/resourceGroups/Silvervine/providers/Microsoft.OperationalInsights/workspaces/PTS-WEB-STAGING
At C:\Program Files\WindowsPowerShell\Modules\Az.ApplicationInsights\2.2.5\ApplicationInsights.Autorest\custom\New-AzApplicationInsights.ps1:234 char:9
+ . Az.ApplicationInsights.internal\New-AzApplicationInsights @ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ({ ResourceGroup...fab0000\""
} }:<>f__AnonymousType0`4) [New-AzApplicationInsights_CreateExpanded], Exception
+ FullyQualifiedErrorId : BadRequest,Microsoft.Azure.PowerShell.Cmdlets.ApplicationInsights.Cmdlets.NewAzApplicationInsights_CreateExpanded
SOLUTION: You must go into the resource and using the warning message at the top, configure the right workspace. Using the properties does not seem to fix it.
--------------------------------------------------------------------------------------------------------------------------------------------------------------
#>
$resources = Get-AzApplicationInsights
foreach ($resource in $resources) {
if (-not ($resource.DisableIPMasking)) {
Write-Output "Updating resource: $($resource.Name)"
Update-AzApplicationInsights -Name $resource.Name -ResourceGroupName $resource.ResourceGroupName -DisableIPMasking:$true | Select-Object ApplicationId, DisableIPMasking
}
}
Write-Output "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment