[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) | 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; }