Created
July 28, 2025 07:56
-
-
Save DJStompZone/922b4defce2165dfea849b8ea653868e to your computer and use it in GitHub Desktop.
Update PSReadLine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Updates PSReadLine module cleanly. | |
.DESCRIPTION | |
Uninstalls older conflicting versions of PSReadLine and installs the latest version | |
from the PowerShell Gallery. Ensures the latest version is imported. | |
.NOTES | |
Author: Dylan Magar <[email protected]> | |
License: MIT | |
GitHub: https://github.com/djstompzone/placeholder | |
#> | |
# Optional: elevate if running without admin rights | |
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { | |
Write-Host "Relaunching as administrator..." | |
Start-Process powershell -Verb runAs -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -File `"" + $MyInvocation.MyCommand.Path + "`"") | |
exit | |
} | |
# Install PowerShellGet if needed | |
if (-not (Get-Command Install-Module -ErrorAction SilentlyContinue)) { | |
Write-Host "Installing PowerShellGet..." | |
Install-PackageProvider -Name NuGet -Force | |
Install-Module PowerShellGet -Force | |
} | |
# Ensure NuGet is available | |
if (-not (Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue)) { | |
Install-PackageProvider -Name NuGet -Force | |
} | |
# Uninstall older conflicting versions | |
$installed = Get-InstalledModule -Name PSReadLine -AllVersions -ErrorAction SilentlyContinue | |
if ($installed) { | |
foreach ($ver in $installed) { | |
Write-Host "Removing old PSReadLine version $($ver.Version)..." | |
Uninstall-Module -Name PSReadLine -RequiredVersion $ver.Version -Force -ErrorAction SilentlyContinue | |
} | |
} | |
# Install latest | |
Write-Host "Installing latest PSReadLine..." | |
Install-Module -Name PSReadLine -Force -AllowClobber | |
# Force import it | |
Import-Module PSReadLine -Force | |
# Confirm | |
$ver = Get-Module PSReadLine | Select-Object -ExpandProperty Version | |
Write-Host "PSReadLine updated to version $ver" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment