Last week while working with Azure PowerShell, I came across this specific need to build a solid logging framework wherein all the information would be dumped from the PowerShell and could be used to build reporting features. Having worked with Azure for quite some time, my quick response was – hey, why don’t we use Azure applications insights here? It has already got all the base framework needed and Azure portal gives flexibility to show the logged information effectively. So yeah – sounds that’s the right candidate!
But wait, having said that we will be logging information from PowerShell and not from any .NET based application so how do we achieve it? Do I need to search if Azure Application Insights has any public endpoints which I need to consume from my PowerShell script?
After few hours of searching, I got the solution and believe me it’s quite an easy one and ‘readymade-ish’.
Since Application insights already provides managed APIs to work with it using any .NET based application and Windows PowerShell is based on Windows platform too so we can directly import any managed assembly to PowerShell and use it’s methods. Let’s start it by obtaining core assembly required for Application Insight logging which is Microsoft.ApplicationInsights.
You can get it simply by creating a sample console application and installing an Application Insights nugget in it.
Install-Package Microsoft.ApplicationInsights -Version 2.0.1
Once the nuget is installed, Microsoft.ApplicationInsights assembly will be added in your console application references. Right click on it and navigate to by copying its path. Copy the assembly and paste it in folder where you will be creating your PowerShell commands.
Next step is to create Azure application insights service which will be used as logging repository. You can use azure portal to create it. Very well step by step documentation related to same is available here, you can refer to it if you are not familiar with the creation process.
Once it is created, navigate to the properties tab and copy instrumentation key. Now open up PowerShell editor and load application insight assembly into it.
- Clear-Host
- Add-Type -Path "[Your_Assembly_Path]\Microsoft.ApplicationInsights.dll"
Now since we have loaded the .NET assembly in PowerShell, we can create object of underlying classes in the assembly and access all public methods of those classes.



Kuppurasu NagarajPosted May 17, 2016, 11:32 AM
Nice sharing..
Prasanna MuraliPosted May 14, 2016, 9:25 AM
Nice one
Bhushan GawalePosted May 14, 2016, 9:22 AM
Thanks guys!
Prasham SabadraPosted May 14, 2016, 8:15 AM
Thanks Bhushan for sharing !!!
Debasis SahaPosted May 14, 2016, 3:52 AM
Good..