add: method to avoid assembly already loaded error
This commit is contained in:
@@ -8,6 +8,7 @@ The format is based on and uses the types of changes according to [Keep a Change
|
||||
|
||||
- Added additional error handling to connect function to identify problematic steps when they occur.
|
||||
- Added new method of verifying spo tenant for Connect-SPOService branch of connect function.
|
||||
- Added method to avoid "assembly already loaded" error in PNP Powershell function on first run, subsequent runs in the same session will still throw the error.
|
||||
|
||||
## [0.1.26] - 2024-08-04
|
||||
|
||||
|
@@ -5,7 +5,7 @@ Import-Module .\output\module\M365FoundationsCISReport\*\*.psd1
|
||||
|
||||
|
||||
<#
|
||||
$ver = "v0.1.26"
|
||||
$ver = "v0.1.27"
|
||||
git checkout main
|
||||
git pull origin main
|
||||
git tag -a $ver -m "Release version $ver refactor Update"
|
||||
|
@@ -20,6 +20,17 @@ function Assert-ModuleAvailability {
|
||||
else {
|
||||
Write-Verbose "$ModuleName module is already at required version or newer."
|
||||
}
|
||||
if ($ModuleName -eq "Microsoft.Graph") {
|
||||
# "Preloading Microsoft.Graph assembly to prevent type-loading issues..."
|
||||
Write-Verbose "Preloading Microsoft.Graph assembly to prevent type-loading issues..."
|
||||
try {
|
||||
# Run a harmless cmdlet to preload the assembly
|
||||
Get-MgGroup -Top 1 -ErrorAction SilentlyContinue | Out-Null
|
||||
}
|
||||
catch {
|
||||
Write-Verbose "Could not preload Microsoft.Graph assembly. Error: $_"
|
||||
}
|
||||
}
|
||||
if ($SubModules.Count -gt 0) {
|
||||
foreach ($subModule in $SubModules) {
|
||||
Write-Verbose "Importing submodule $ModuleName.$subModule..."
|
||||
@@ -30,11 +41,9 @@ function Assert-ModuleAvailability {
|
||||
Write-Verbose "Importing module $ModuleName..."
|
||||
Import-Module -Name $ModuleName -RequiredVersion $RequiredVersion -ErrorAction Stop -WarningAction SilentlyContinue | Out-Null
|
||||
}
|
||||
|
||||
}
|
||||
catch {
|
||||
throw "Assert-ModuleAvailability:`n$_"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user