Update PSM1 file to properly load assemblies and let PowerShell handle cmdlet export

This commit is contained in:
GraceSolutions
2025-04-15 00:44:55 -04:00
parent 2916619bf3
commit 412f46ec8d
14 changed files with 95 additions and 234 deletions
+36
View File
@@ -0,0 +1,36 @@
# Load assemblies from the lib folder using System.Reflection.Assembly::LoadBytes
# This avoids file lock issues when the module is loaded
$libPath = Join-Path $PSScriptRoot -ChildPath "lib"
$DLLFileList = Get-ChildItem -Path $libPath -Filter "*.dll"
$DLLFileListCount = ($DLLFileList | Measure-Object).Count
$DLLFileListCounter = 1
For ($DLLFileListIndex = 0; $DLLFileListIndex -lt $DLLFileListCount; $DLLFileListIndex++)
{
Try
{
$DLLFile = $DLLFileList[$DLLFileListIndex]
Write-Verbose "Attempting to load DLL assembly $($DLLFileListCounter) of $($DLLFileListCount). Please Wait..."
Write-Verbose "Path: $($DLLFile)"
$DLLFileBytes = [System.IO.File]::ReadAllBytes($DLLFile.FullName)
$Null = [System.Reflection.Assembly]::Load($DLLFileBytes)
Write-Verbose "Successfully loaded DLL assembly $($DLLFileListCounter) of $($DLLFileListCount)"
}
Catch
{
Write-Warning "Failed to load DLL assembly $($DLLFileListCounter) of $($DLLFileListCount): $($_.Exception.Message)"
}
Finally
{
$DLLFileListCounter++
}
}