ps/Modules/Alkami.PowerShell.SDK/tools/chocolateyInstall.ps1
2023-05-30 22:51:22 -07:00

39 lines
1.5 KiB
PowerShell

[CmdletBinding()]
Param()
process {
$myCurrentPath = $PSScriptRoot;
Write-Verbose "Installing the Module from $myCurrentPath";
$parentPath = (Split-Path $myCurrentPath);
$systemModulePath = "C:\Program Files\WindowsPowerShell\Modules\";
$myModulePath = (Join-Path $parentPath "module");
$metadata = ([Xml](Get-Content (Join-Path $parentPath "*.nuspec"))).package.metadata;
$id = $metadata.id;
$version = $metadata.version -replace '-pre.+','';
$targetModulePath = (Join-Path $systemModulePath $id);
$targetModuleVersionPath = (Join-Path $targetModulePath $version);
if (Test-Path $targetModulePath) {
## If the target folder already existed, remove it, because we are re-installing this package, obviously
if (Test-Path $targetModuleVersionPath) {
Write-Warning "Found an already existing module at [$targetModuleVersionPath]!!"
Remove-Item $targetModuleVersionPath -Recurse -Force;
}
## Clear previous children for name conflicts
(Get-ChildItem $targetModulePath) | % {
Write-Information "Removing module located at [$_]";
Remove-Item $_.FullName -Recurse -Force;
}
}
Write-Debug "Copying module $id to [$targetModuleVersionPath]";
Copy-Item $myModulePath -Destination $targetModuleVersionPath -Recurse -Force;
## Ensure the module was able to load
Import-Module $id -Global;
}