Using Managed Identity for Application Insights in Powershell

Anna Kosiorek 0 Reputation points Microsoft Employee
2024-05-09T11:38:53.63+00:00

Hello, we are using logging with Application Insights in our Powershell scripts.

We would like to move and use the Managed Identity with Connection String auth. I couldn't find resources how to do so. https://learn.microsoft.com/en-us/azure/azure-monitor/app/azure-ad-authentication?tabs=net does not show Powershell.

With transition to connection string–based ingestion support I received how to move to using Connection Strings:

Add-Type -Path "c:\users\username}\.nuget\packages\microsoft.applicationinsights\2.20.0\lib\netstandard2.0\Microsoft.ApplicationInsights.dll"
$tconf = New-Object Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration 
$tconf.ConnectionString = $config.root.ConnectionString
$tc = New-Object Microsoft.ApplicationInsights.TelemetryClient($tconf)
$tc.TelemetryConfiguration.ConnectionString
$tc.TrackTrace("Sample Trace Message") 
$tc.Flush()

Is there a way to provide ClientId of the Identity like we do in C#:

//[...]
var credential = new Azure.Identity.ManagedIdentityCredential(ClientId);
configuration.SetAzureTokenCredential(credential);
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,134 questions
0 comments No comments
{count} votes