@@ -51,6 +51,9 @@ public sealed class ImportModuleCommand : ModuleCmdletBase, IDisposable
5151 private const string ParameterSet_ViaPsrpSession = "PSSession" ;
5252 private const string ParameterSet_ViaCimSession = "CimSession" ;
5353 private const string ParameterSet_FQName_ViaPsrpSession = "FullyQualifiedNameAndPSSession" ;
54+ private const string ParameterSet_ViaWinCompat = "WinCompat" ;
55+ private const string ParameterSet_FQName_ViaWinCompat = "FullyQualifiedNameAndWinCompat" ;
56+
5457
5558 /// <summary>
5659 /// This parameter specifies whether to import to the current session state
@@ -82,6 +85,7 @@ public string Prefix
8285 [ Parameter ( ParameterSetName = ParameterSet_Name , Mandatory = true , ValueFromPipeline = true , Position = 0 ) ]
8386 [ Parameter ( ParameterSetName = ParameterSet_ViaPsrpSession , Mandatory = true , ValueFromPipeline = true , Position = 0 ) ]
8487 [ Parameter ( ParameterSetName = ParameterSet_ViaCimSession , Mandatory = true , ValueFromPipeline = true , Position = 0 ) ]
88+ [ Parameter ( "PSWindowsPowerShellCompatibility" , ExperimentAction . Show , ParameterSetName = ParameterSet_ViaWinCompat , Mandatory = true , ValueFromPipeline = true , Position = 0 ) ]
8589 [ ValidateTrustedData ]
8690 [ SuppressMessage ( "Microsoft.Performance" , "CA1819:PropertiesShouldNotReturnArrays" , Justification = "Cmdlets use arrays for parameters." ) ]
8791 public string [ ] Name { set ; get ; } = Array . Empty < string > ( ) ;
@@ -91,6 +95,7 @@ public string Prefix
9195 /// </summary>
9296 [ Parameter ( ParameterSetName = ParameterSet_FQName , Mandatory = true , ValueFromPipeline = true , Position = 0 ) ]
9397 [ Parameter ( ParameterSetName = ParameterSet_FQName_ViaPsrpSession , Mandatory = true , ValueFromPipeline = true , Position = 0 ) ]
98+ [ Parameter ( "PSWindowsPowerShellCompatibility" , ExperimentAction . Show , ParameterSetName = ParameterSet_FQName_ViaWinCompat , Mandatory = true , ValueFromPipeline = true , Position = 0 ) ]
9499 [ ValidateTrustedData ]
95100 [ SuppressMessage ( "Microsoft.Performance" , "CA1819:PropertiesShouldNotReturnArrays" , Justification = "Cmdlets use arrays for parameters." ) ]
96101 public ModuleSpecification [ ] FullyQualifiedName { get ; set ; }
@@ -226,8 +231,15 @@ public SwitchParameter Force
226231
227232 /// <summary>
228233 /// Skips the check on CompatiblePSEditions for modules loaded from the System32 module path.
234+ /// This is mutually exclusive with UseWindowsPowerShell parameter.
229235 /// </summary>
230- [ Parameter ]
236+ [ Parameter ( ParameterSetName = ParameterSet_Name ) ]
237+ [ Parameter ( ParameterSetName = ParameterSet_FQName ) ]
238+ [ Parameter ( ParameterSetName = ParameterSet_ModuleInfo ) ]
239+ [ Parameter ( ParameterSetName = ParameterSet_Assembly ) ]
240+ [ Parameter ( ParameterSetName = ParameterSet_ViaPsrpSession ) ]
241+ [ Parameter ( ParameterSetName = ParameterSet_ViaCimSession ) ]
242+ [ Parameter ( ParameterSetName = ParameterSet_FQName_ViaPsrpSession ) ]
231243 public SwitchParameter SkipEditionCheck
232244 {
233245 get { return ( SwitchParameter ) BaseSkipEditionCheck ; }
@@ -263,6 +275,7 @@ public SwitchParameter AsCustomObject
263275 [ Parameter ( ParameterSetName = ParameterSet_Name ) ]
264276 [ Parameter ( ParameterSetName = ParameterSet_ViaPsrpSession ) ]
265277 [ Parameter ( ParameterSetName = ParameterSet_ViaCimSession ) ]
278+ [ Parameter ( "PSWindowsPowerShellCompatibility" , ExperimentAction . Show , ParameterSetName = ParameterSet_ViaWinCompat ) ]
266279 [ Alias ( "Version" ) ]
267280 public Version MinimumVersion
268281 {
@@ -277,6 +290,7 @@ public Version MinimumVersion
277290 [ Parameter ( ParameterSetName = ParameterSet_Name ) ]
278291 [ Parameter ( ParameterSetName = ParameterSet_ViaPsrpSession ) ]
279292 [ Parameter ( ParameterSetName = ParameterSet_ViaCimSession ) ]
293+ [ Parameter ( "PSWindowsPowerShellCompatibility" , ExperimentAction . Show , ParameterSetName = ParameterSet_ViaWinCompat ) ]
280294 public string MaximumVersion
281295 {
282296 get
@@ -306,6 +320,7 @@ public string MaximumVersion
306320 [ Parameter ( ParameterSetName = ParameterSet_Name ) ]
307321 [ Parameter ( ParameterSetName = ParameterSet_ViaPsrpSession ) ]
308322 [ Parameter ( ParameterSetName = ParameterSet_ViaCimSession ) ]
323+ [ Parameter ( "PSWindowsPowerShellCompatibility" , ExperimentAction . Show , ParameterSetName = ParameterSet_ViaWinCompat ) ]
309324 public Version RequiredVersion
310325 {
311326 get { return BaseRequiredVersion ; }
@@ -406,6 +421,15 @@ public ImportModuleCommand()
406421 [ ValidateNotNullOrEmpty ]
407422 public string CimNamespace { get ; set ; }
408423
424+ /// <summary>
425+ /// This parameter causes a module to be loaded into Windows PowerShell.
426+ /// This is mutually exclusive with SkipEditionCheck parameter.
427+ /// </summary>
428+ [ Parameter ( "PSWindowsPowerShellCompatibility" , ExperimentAction . Show , ParameterSetName = ParameterSet_ViaWinCompat , Mandatory = true ) ]
429+ [ Parameter ( "PSWindowsPowerShellCompatibility" , ExperimentAction . Show , ParameterSetName = ParameterSet_FQName_ViaWinCompat , Mandatory = true ) ]
430+ [ Alias ( "UseWinPS" ) ]
431+ public SwitchParameter UseWindowsPowerShell { get ; set ; }
432+
409433 #endregion Cmdlet parameters
410434
411435 #region Local import
@@ -805,7 +829,8 @@ private IList<PSModuleInfo> ImportModule_RemotelyViaPsrpSession(
805829 ImportModuleOptions importModuleOptions ,
806830 IEnumerable < string > moduleNames ,
807831 IEnumerable < ModuleSpecification > fullyQualifiedNames ,
808- PSSession psSession )
832+ PSSession psSession ,
833+ bool usingWinCompat = false )
809834 {
810835 var remotelyImportedModules = new List < PSModuleInfo > ( ) ;
811836 if ( moduleNames != null )
@@ -829,7 +854,7 @@ private IList<PSModuleInfo> ImportModule_RemotelyViaPsrpSession(
829854 // Send telemetry on the imported modules
830855 foreach ( PSModuleInfo moduleInfo in remotelyImportedModules )
831856 {
832- ApplicationInsightsTelemetry . SendTelemetryMetric ( TelemetryType . ModuleLoad , moduleInfo . Name ) ;
857+ ApplicationInsightsTelemetry . SendTelemetryMetric ( usingWinCompat ? TelemetryType . WinCompatModuleLoad : TelemetryType . ModuleLoad , moduleInfo . Name ) ;
833858 }
834859
835860 return remotelyImportedModules ;
@@ -1795,11 +1820,15 @@ protected override void ProcessRecord()
17951820 {
17961821 SetModuleBaseForEngineModules ( foundModule . Name , this . Context ) ;
17971822
1798- // Telemetry here - report module load
1799- ApplicationInsightsTelemetry . SendTelemetryMetric ( TelemetryType . ModuleLoad , foundModule . Name ) ;
1823+ // report loading of the module in telemetry
1824+ // avoid double reporting for WinCompat modules that go through CommandDiscovery\AutoloadSpecifiedModule
1825+ if ( ! foundModule . IsWindowsPowerShellCompatModule )
1826+ {
1827+ ApplicationInsightsTelemetry . SendTelemetryMetric ( TelemetryType . ModuleLoad , foundModule . Name ) ;
18001828#if LEGACYTELEMETRY
1801- TelemetryAPI . ReportModuleLoad ( foundModule ) ;
1829+ TelemetryAPI . ReportModuleLoad ( foundModule ) ;
18021830#endif
1831+ }
18031832 }
18041833 }
18051834 }
@@ -1836,6 +1865,25 @@ protected override void ProcessRecord()
18361865 ApplicationInsightsTelemetry . SendTelemetryMetric ( TelemetryType . ModuleLoad , modulespec . Name ) ;
18371866 }
18381867 }
1868+ else if ( this . ParameterSetName . Equals ( ParameterSet_ViaWinCompat , StringComparison . OrdinalIgnoreCase )
1869+ || this . ParameterSetName . Equals ( ParameterSet_FQName_ViaWinCompat , StringComparison . OrdinalIgnoreCase ) )
1870+ {
1871+ if ( this . UseWindowsPowerShell )
1872+ {
1873+ var WindowsPowerShellCompatRemotingSession = CreateWindowsPowerShellCompatResources ( ) ;
1874+ if ( WindowsPowerShellCompatRemotingSession != null )
1875+ {
1876+ foreach ( PSModuleInfo moduleProxy in ImportModule_RemotelyViaPsrpSession ( importModuleOptions , this . Name , this . FullyQualifiedName , WindowsPowerShellCompatRemotingSession , true ) )
1877+ {
1878+ moduleProxy . IsWindowsPowerShellCompatModule = true ;
1879+ System . Threading . Interlocked . Increment ( ref s_WindowsPowerShellCompatUsageCounter ) ;
1880+
1881+ string message = StringUtil . Format ( Modules . WinCompatModuleWarning , moduleProxy . Name , WindowsPowerShellCompatRemotingSession . Name ) ;
1882+ WriteWarning ( message ) ;
1883+ }
1884+ }
1885+ }
1886+ }
18391887 else
18401888 {
18411889 Dbg . Assert ( false , "Unrecognized parameter set" ) ;
0 commit comments