mirror of
https://github.com/freedbygrace/PSOPNSenseAPI.git
synced 2026-07-27 20:29:11 +00:00
Update PSM1 file to properly load assemblies and let PowerShell handle cmdlet export
This commit is contained in:
@@ -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++
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user