[CmdletBinding()] Param() process { $myCurrentPath = $PSScriptRoot; Write-Verbose "Installing the Module from $myCurrentPath"; ###### ## Begin Very Special Logic ###### ## Kill Alkami.DevOps.Deployment if it exists. This is a legacy concern $pathToKill = "c:\Program Files\WindowsPowerShell\Modules\Alkami.DevOps.Deployment"; if (Test-Path $pathToKill) { Remove-Item $pathToKill -Recurse -Force; } $chocoInstallPath = Get-ChocolateyInstallPath $pathToKill = Join-Path $chocoInstallPath "lib\Alkami.DevOps.Deployment" if (Test-Path $pathToKill) { Remove-Item $pathToKill -Recurse -Force; } ###### ## End Very Special Logic ###### $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) | ForEach-Object { Write-Information "Removing module located at [$_]"; Remove-Item $_.FullName -Recurse -Force; } } Write-Host "Copying module $id to [$targetModuleVersionPath]"; Copy-Item $myModulePath -Destination $targetModuleVersionPath -Recurse -Force; $resourcesFolder = (Join-Path $parentPath "Resources") if (Test-Path $resourcesFolder) { Write-Host "Copying resources folder for module $id to [$targetModuleVersionPath]" Copy-Item $resourcesFolder -Destination $targetModuleVersionPath -Recurse -Force } }