Created
November 19, 2025 15:42
-
-
Save celsowm/67930507bd1fccb480c599b576e509fe to your computer and use it in GitHub Desktop.
update powershell to v7
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
| # Script único para instalar/atualizar PowerShell 7 (pwsh) no Windows 11 | |
| Write-Host "==> Atualizando/instalando PowerShell 7..." -ForegroundColor Cyan | |
| # Garante TLS 1.2 pra falar com GitHub | |
| [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
| # Função pra verificar se winget existe | |
| function Test-Winget { | |
| return [bool](Get-Command winget -ErrorAction SilentlyContinue) | |
| } | |
| if (Test-Winget) { | |
| Write-Host "==> winget encontrado. Instalando/atualizando via winget..." -ForegroundColor Green | |
| winget install --id Microsoft.PowerShell --source winget ` | |
| --accept-package-agreements --accept-source-agreements | |
| Write-Host "==> Concluído via winget. Abra um novo terminal e rode: pwsh" -ForegroundColor Green | |
| } | |
| else { | |
| Write-Host "==> winget NÃO encontrado. Indo pelo caminho GitHub (MSI)..." -ForegroundColor Yellow | |
| $releaseApi = "https://api.github.com/repos/PowerShell/PowerShell/releases/latest" | |
| try { | |
| $release = Invoke-RestMethod -Uri $releaseApi -UseBasicParsing | |
| } | |
| catch { | |
| Write-Host "ERRO: Não consegui acessar o GitHub Releases da PowerShell." -ForegroundColor Red | |
| Write-Host "Detalhes: $($_.Exception.Message)" -ForegroundColor Red | |
| exit 1 | |
| } | |
| $asset = $release.assets | Where-Object { $_.name -like "PowerShell-*-win-x64.msi" } | Select-Object -First 1 | |
| if (-not $asset) { | |
| Write-Host "ERRO: Não achei MSI win-x64 na release mais recente." -ForegroundColor Red | |
| exit 1 | |
| } | |
| $downloadUrl = $asset.browser_download_url | |
| $tempMsi = Join-Path $env:TEMP $asset.name | |
| Write-Host "==> Baixando: $($asset.name)" -ForegroundColor Cyan | |
| Write-Host " De: $downloadUrl" -ForegroundColor DarkGray | |
| Write-Host " Para: $tempMsi" -ForegroundColor DarkGray | |
| $ProgressPreference = 'SilentlyContinue' | |
| Invoke-WebRequest -Uri $downloadUrl -OutFile $tempMsi | |
| Write-Host "==> Iniciando instalação silenciosa do PowerShell 7..." -ForegroundColor Cyan | |
| Start-Process msiexec.exe -ArgumentList "/i `"$tempMsi`" /passive" -Wait | |
| Write-Host "==> Instalação concluída (via MSI)." -ForegroundColor Green | |
| Write-Host " Abra um novo terminal e rode: pwsh" -ForegroundColor Green | |
| } | |
| Write-Host "" | |
| Write-Host "Dica: no novo PowerShell, confira a versão com:" -ForegroundColor Cyan | |
| Write-Host " pwsh" -ForegroundColor Yellow | |
| Write-Host " `$PSVersionTable" -ForegroundColor Yellow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment