1010using System . Linq ;
1111using System . Management . Automation ;
1212using System . Management . Automation . Internal ;
13+ using System . Management . Automation . Language ;
1314using System . Management . Automation . Runspaces ;
1415using System . Reflection ;
1516using System . Security ;
1617using System . Threading ;
1718
1819using Microsoft . Management . Infrastructure ;
1920using Microsoft . PowerShell . Cmdletization ;
21+ using Microsoft . PowerShell . Telemetry ;
2022
2123using Dbg = System . Management . Automation . Diagnostics ;
22-
23- using System . Management . Automation . Language ;
2424using Parser = System . Management . Automation . Language . Parser ;
2525using ScriptBlock = System . Management . Automation . ScriptBlock ;
2626using Token = System . Management . Automation . Language . Token ;
27+
2728#if LEGACYTELEMETRY
2829using Microsoft . PowerShell . Telemetry . Internal ;
2930#endif
@@ -825,6 +826,12 @@ private IList<PSModuleInfo> ImportModule_RemotelyViaPsrpSession(
825826 }
826827 }
827828
829+ // Send telemetry on the imported modules
830+ foreach ( PSModuleInfo moduleInfo in remotelyImportedModules )
831+ {
832+ ApplicationInsightsTelemetry . SendTelemetryMetric ( TelemetryType . ModuleLoad , moduleInfo . Name ) ;
833+ }
834+
828835 return remotelyImportedModules ;
829836 }
830837
@@ -1251,6 +1258,7 @@ private void ImportModule_RemotelyViaCimSession(
12511258 foreach ( RemoteDiscoveryHelper . CimModule remoteCimModule in remotePsCimModules )
12521259 {
12531260 ImportModule_RemotelyViaCimModuleData ( importModuleOptions , remoteCimModule , cimSession ) ;
1261+ ApplicationInsightsTelemetry . SendTelemetryMetric ( TelemetryType . ModuleLoad , remoteCimModule . ModuleName ) ;
12541262 }
12551263 }
12561264
@@ -1743,6 +1751,7 @@ protected override void ProcessRecord()
17431751 // of doing Get-Module -list
17441752 foreach ( PSModuleInfo module in ModuleInfo )
17451753 {
1754+ ApplicationInsightsTelemetry . SendTelemetryMetric ( TelemetryType . ModuleLoad , module . Name ) ;
17461755 RemoteDiscoveryHelper . DispatchModuleInfoProcessing (
17471756 module ,
17481757 localAction : delegate ( )
@@ -1772,6 +1781,7 @@ protected override void ProcessRecord()
17721781 {
17731782 foreach ( Assembly suppliedAssembly in Assembly )
17741783 {
1784+ ApplicationInsightsTelemetry . SendTelemetryMetric ( TelemetryType . ModuleLoad , suppliedAssembly . GetName ( ) . Name ) ;
17751785 ImportModule_ViaAssembly ( importModuleOptions , suppliedAssembly ) ;
17761786 }
17771787 }
@@ -1785,6 +1795,8 @@ protected override void ProcessRecord()
17851795 {
17861796 SetModuleBaseForEngineModules ( foundModule . Name , this . Context ) ;
17871797
1798+ // Telemetry here - report module load
1799+ ApplicationInsightsTelemetry . SendTelemetryMetric ( TelemetryType . ModuleLoad , foundModule . Name ) ;
17881800#if LEGACYTELEMETRY
17891801 TelemetryAPI . ReportModuleLoad ( foundModule ) ;
17901802#endif
@@ -1809,6 +1821,7 @@ protected override void ProcessRecord()
18091821 BaseGuid = modulespec . Guid ;
18101822
18111823 PSModuleInfo foundModule = ImportModule_LocallyViaName ( importModuleOptions , modulespec . Name ) ;
1824+ ApplicationInsightsTelemetry . SendTelemetryMetric ( TelemetryType . ModuleLoad , modulespec . Name ) ;
18121825 if ( foundModule != null )
18131826 {
18141827 SetModuleBaseForEngineModules ( foundModule . Name , this . Context ) ;
@@ -1818,6 +1831,10 @@ protected override void ProcessRecord()
18181831 else if ( this . ParameterSetName . Equals ( ParameterSet_FQName_ViaPsrpSession , StringComparison . OrdinalIgnoreCase ) )
18191832 {
18201833 ImportModule_RemotelyViaPsrpSession ( importModuleOptions , null , FullyQualifiedName , this . PSSession ) ;
1834+ foreach ( ModuleSpecification modulespec in FullyQualifiedName )
1835+ {
1836+ ApplicationInsightsTelemetry . SendTelemetryMetric ( TelemetryType . ModuleLoad , modulespec . Name ) ;
1837+ }
18211838 }
18221839 else
18231840 {
0 commit comments