.PARAMETER Cleanup Remove installation files after successful installation.
switch ($OS) "Windows" return "win-x64\.msi$" "macOS" return "osx-x64\.pkg$" "Linux" return "linux-x64\.tar\.gz$" default return ".*"
$msiArguments = @( "/i `"$InstallerPath`"", "/quiet", "/norestart", "ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1", "ENABLE_PSREMOTING=1", "REGISTER_MANIFEST=1" ) update powershell version
function Get-LatestPowerShellVersion param( [bool]$IncludePreview = $false, [string]$Channel = "Stable" )
switch ($os) "Windows" $pwshPaths = @( "$env:ProgramFiles\PowerShell\*", "$env:LocalAppData\Microsoft\PowerShell\*" ) "macOS" $pwshPaths = @("/usr/local/microsoft/powershell/*") "Linux" $pwshPaths = @("/opt/microsoft/powershell/*") update powershell version
if (-not $versionInfo) Write-ColorOutput "Failed to get version information. Exiting." "Red" exit 1
function Install-OnWindows param( [string]$InstallerPath, [string]$Version ) update powershell version
if ($os -eq "Unknown") Write-ColorOutput "Unsupported operating system!" "Red" exit 1 if ($os -eq "Windows" -and -not (Test-Administrator)) Write-ColorOutput "Warning: Administrator privileges recommended for installation." "Yellow" Write-ColorOutput "Attempting to restart with elevated privileges..." "Yellow"