Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Last active December 25, 2015 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/3690876dbfe9c1e3c2b2 to your computer and use it in GitHub Desktop.
Save guitarrapc/3690876dbfe9c1e3c2b2 to your computer and use it in GitHub Desktop.
Copy dll and Import-Module copied dll
# 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 *;
@guitarrapc
Copy link
Author

animation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment