@@ -1736,7 +1736,7 @@ function Confirm-M365DSCModuleDependency
1736
1736
1737
1737
$Global :MaximumFunctionCount = 32767
1738
1738
1739
- if ($Global :SkipModuleValidation )
1739
+ if ($Global :IsTestEnvironment )
1740
1740
{
1741
1741
Write-Verbose - Message " Skipping module dependency validation in test environment for module '$ModuleName '."
1742
1742
return
@@ -3899,7 +3899,7 @@ function Get-M365DSCExportContentForResource
3899
3899
3900
3900
$primaryKey = ' '
3901
3901
$ModuleFullName = " MSFT_" + $ResourceName
3902
- if ($null -eq $Script :AllM365DscResources )
3902
+ if ($null -eq $Script :AllM365DscResources -and -not $ Global :IsTestEnvironment )
3903
3903
{
3904
3904
$Script :AllM365DscResources = [System.Collections.Generic.Dictionary [System.String , System.Object ]]::new([System.StringComparer ]::InvariantCultureIgnoreCase)
3905
3905
if ($Script :IsPowerShellCore )
@@ -3916,14 +3916,16 @@ function Get-M365DSCExportContentForResource
3916
3916
}
3917
3917
}
3918
3918
3919
- $Resource = $Script :AllM365DscResources [ $ResourceName ]
3919
+ $Resource = $Script :AllM365DscResources . $ResourceName
3920
3920
$Keys = $Resource.Properties.Where ({ $_.IsMandatory }) | `
3921
3921
Select-Object - ExpandProperty Name
3922
3922
if ($null -eq $keys )
3923
3923
{
3924
- Import-Module $Resource.Path - Force
3925
- $moduleInfo = Get-Command - Module $ModuleFullName - ErrorAction SilentlyContinue
3926
- $cmdInfo = $moduleInfo | Where-Object - FilterScript {$_.Name -eq ' Get-TargetResource' }
3924
+ if (-not (Get-Module $ModuleFullName ))
3925
+ {
3926
+ Import-Module $Resource.Path - Force
3927
+ }
3928
+ $cmdInfo = Get-Command $ModuleFullName \Get-TargetResource - ErrorAction SilentlyContinue
3927
3929
$Keys = $cmdInfo.Parameters.Values.Where ({ $_.ParameterSets.Values.IsMandatory }).Name
3928
3930
}
3929
3931
0 commit comments