# GoatCMS CLI uninstaller for Windows. # Generated from herd/dist.json by @goatcms/herd/dist/installers.goat. # # irm https://goatcms.com/dist/uninstall.ps1 | iex # # Removes the commands installed by install.ps1 (default: all of them) and # their directories from PATH. $env:GOAT_APP and $env:GOAT_INSTALL_DIR # select commands and a custom installation directory. [CmdletBinding()] param( [string]$App = $env:GOAT_APP, [string]$InstallDir = $env:GOAT_INSTALL_DIR ) $ErrorActionPreference = 'Stop' $commands = @('goat') $dirTemplates = @('%ProgramFiles%\GoatCMS') $apps = if ($App) { @($App -split '[,\s]+' | Where-Object { $_ }) } else { $commands } foreach ($name in $apps) { if ($commands -notcontains $name) { throw "Unknown command: $name (available: $($commands -join ', '))" } } $removedDirs = @() $removed = 0 foreach ($name in $apps) { $dirs = if ($InstallDir) { @($InstallDir) } else { $dirTemplates | ForEach-Object { [Environment]::ExpandEnvironmentVariables($_.Replace('{app}', $name)) } } foreach ($dir in ($dirs | Select-Object -Unique)) { $exe = Join-Path $dir "$name.exe" if (Test-Path $exe) { Remove-Item $exe -Force Write-Host "Removed $exe" $removed++ if (-not (Get-ChildItem $dir -Force -ErrorAction SilentlyContinue)) { Remove-Item $dir -Force $removedDirs += $dir } } } } foreach ($target in @('User', 'Machine')) { $current = [Environment]::GetEnvironmentVariable('Path', $target) if (-not $current) { continue } $kept = @(("$current" -split ';') | Where-Object { $entry = $_.TrimEnd('\'); $_ -and -not ($removedDirs | Where-Object { $_.TrimEnd('\') -ieq $entry }) }) $updated = $kept -join ';' if ($updated -ne $current) { try { [Environment]::SetEnvironmentVariable('Path', $updated, $target) Write-Host "Updated the $($target.ToLower()) PATH" } catch { Write-Warning "Run as administrator to remove $($removedDirs -join ', ') from the machine PATH" } } } if ($removed -eq 0) { Write-Host "Nothing to remove for: $($apps -join ', ')" }