// This method will be called for each input received from the pipeline to this cmdlet; if no input is received, this method is not called protected override void ProcessRecord() { // TODO: custom events as json input, ex. Found 960 users in AAD should be - EventName = Found users in AAD and a custom input @{"UsersFound" = 960} MyTelemetryClient.PopulateProperties(_properties, _functionName); //WriteVerbose("Process!"); _telemetryClient.TrackEvent( EventName, _properties ); }
} // end ExceptionMessage // This method will be called for each input received from the pipeline to this cmdlet; if no input is received, this method is not called protected override void ProcessRecord() { WriteVerbose("Populating properties..."); MyTelemetryClient.PopulateProperties(_properties, _scriptName, _scriptLineNumber, _functionName, _stackTrace, _exception); string msg = ExceptionMessage(); WriteVerbose("\nException message:\n" + msg); // often of type RuntimeException in PowerShell? WriteVerbose("Exception is of type " + _exception.GetType()); /* * TODO: look at type of ErrorRecord.Exception and create exception of same type. * Can maybe use some reflection to do this? * Activator.CreateInstance ? * maybe cast to the respective type? * * * If we just use ErrorRecord.Exception instead of creating a new Exception * it is always System.Exception in the AI portal * and the message is: Exception of type 'System.Exception' was thrown * this is why we are rolling our own here */ Exception exception = new Exception( msg ); /* * TODO: * Failed method - is in the portal, how do we input that? */ WriteVerbose("Tracking exception"); _telemetryClient.TrackException( exception, _properties ); } // end ProcessRecord
} // end PopulateProperties public static void PopulateProperties(IDictionary <string, string> properties, String functionName) { MyTelemetryClient.PopulateProperties(properties, null, -1, functionName, null, null); } // end PopulateProperties