Last active
December 25, 2015 15:48
-
-
Save guitarrapc/3690876dbfe9c1e3c2b2 to your computer and use it in GitHub Desktop.
Copy dll and Import-Module copied dll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find Module Path | |
$moduleName = "TestModule"; | |
$dllName = "$moduleName.dll"; | |
$cachePath = Join-Path $env:TMP "__cache\$moduleName"; | |
$tempPath = Join-Path $cachePath ([guid]::NewGuid().ToString()); | |
if (Test-Path ".\$dllName") | |
{ | |
$directory = Split-Path (Resolve-Path ".\$dllName").Path -Parent; | |
Copy-Item -Path $directory -Destination $tempPath -Force -Recurse; | |
$path = Join-Path $tempPath $dllName; | |
} | |
else | |
{ | |
$moduleRoot = (Get-Module -ListAvailable -Name $moduleName).ModuleBase; | |
Copy-Item -Path $moduleRoot -Destination $tempPath -Force -Recurse; | |
$path = Join-Path $tempPath $dllName; | |
} | |
# Import as DyanmicModule | |
$module = Import-Module $path -PassThru | |
Export-ModuleMember -Variable * -Cmdlet *; |
Author
guitarrapc
commented
Dec 25, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment