UpdatePowerShellGet.ps1
|
# Update PowerShellGet and PackageManagement # This script runs in a new PowerShell session to avoid module locking issues Write-Host "Starting PowerShellGet/PackageManagement update..." -ForegroundColor Cyan Write-Host "=================================================" -ForegroundColor Cyan Write-Host "" # Check if running as admin $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) if (-not $isAdmin) { Write-Host "ERROR: This script must run with administrator privileges!" -ForegroundColor Red exit 1 } # Show current versions Write-Host "Current versions:" -ForegroundColor Yellow Get-Module -Name PowerShellGet, PackageManagement -ListAvailable | Select-Object Name, Version, Path | Format-Table -AutoSize Write-Host "" Write-Host "Updating PackageManagement..." -ForegroundColor Green try { Install-Module -Name PackageManagement -Force -AllowClobber -Scope AllUsers -ErrorAction Stop Write-Host "PackageManagement updated successfully!" -ForegroundColor Green } catch { Write-Host "ERROR updating PackageManagement: $_" -ForegroundColor Red } Write-Host "" Write-Host "Updating PowerShellGet..." -ForegroundColor Green try { Install-Module -Name PowerShellGet -Force -AllowClobber -Scope AllUsers -ErrorAction Stop Write-Host "PowerShellGet updated successfully!" -ForegroundColor Green } catch { Write-Host "ERROR updating PowerShellGet: $_" -ForegroundColor Red } Write-Host "" Write-Host "Updated versions:" -ForegroundColor Yellow Get-Module -Name PowerShellGet, PackageManagement -ListAvailable | Select-Object Name, Version, Path | Format-Table -AutoSize Write-Host "" Write-Host "=================================================" -ForegroundColor Cyan Write-Host "Update complete! Please close and reopen all PowerShell windows." -ForegroundColor Cyan Write-Host "" Write-Host "Press any key to exit..." $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") |