From 43b6f72227033ce64696a2ab3a380a104d920b25 Mon Sep 17 00:00:00 2001 From: sethvs Date: Tue, 11 Dec 2018 12:59:51 +0300 Subject: [PATCH] Add '.WinModule' exist check. --- WindowsCompatibility/WindowsCompatibility.psm1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/WindowsCompatibility/WindowsCompatibility.psm1 b/WindowsCompatibility/WindowsCompatibility.psm1 index be01ccf..71cbebe 100644 --- a/WindowsCompatibility/WindowsCompatibility.psm1 +++ b/WindowsCompatibility/WindowsCompatibility.psm1 @@ -537,9 +537,12 @@ function Import-WinModule { $module = Import-Module -Name $name -NoClobber @importModuleParameters # Hack using private reflection to keep the proxy module from shadowing the real module. - $null = [PSModuleInfo]. - GetMethod('SetName',[System.Reflection.BindingFlags]'Instance, NonPublic'). - Invoke($module, @($module.Name + '.WinModule')) + if (-not $module.Name.EndsWith('.WinModule', [System.StringComparison]::InvariantCulture)) + { + $null = [PSModuleInfo]. + GetMethod('SetName',[System.Reflection.BindingFlags]'Instance, NonPublic'). + Invoke($module, @($module.Name + '.WinModule')) + } if($PassThru.IsPresent) { $module