RoyalServer.PowerShell.psm1
# # Script module for module 'RoyalServer.PowerShell' # Set-StrictMode -Version Latest $isCore = ($PSVersionTable.Keys -contains "PSEdition") -and ($PSVersionTable.PSEdition -ne 'Desktop') $binarySubPath = '' if ($isCore) { $binarySubPath = 'netcoreapp2.1' } else { $binarySubPath = 'net47' } $script:PSModule = $ExecutionContext.SessionState.Module $script:PSModuleRoot = $script:PSModule.ModuleBase $script:PSRoyalServer = 'RoyalServer.PowerShell.dll' $OneGetModulePath = Join-Path -Path $script:PSModuleRoot -ChildPath $script:PSRoyalServer $binaryModuleRoot = $script:PSModuleRoot if (-not(Test-Path -Path $OneGetModulePath)) { # Import the appropriate nested binary module based on the current PowerShell version $binaryModuleRoot = Join-Path -Path $script:PSModuleRoot -ChildPath $binarySubPath $OneGetModulePath = Join-Path -Path $binaryModuleRoot -ChildPath $script:PSRoyalServer } $OneGetModule = Import-Module -Name $OneGetModulePath -PassThru # When the module is unloaded, remove the nested binary module that was loaded with it if($OneGetModule) { $script:PSModule.OnRemove = { Remove-Module -ModuleInfo $OneGetModule } } |