r/PowerShell • • Mar 04 '20

Announcing PowerShell 7.0 | PowerShell

https://devblogs.microsoft.com/powershell/announcing-powershell-7-0/?WT.mc_id=reddit-social-marouill
281 Upvotes

74 comments sorted by

View all comments

21

u/idontknowwhattouse33 Mar 04 '20
(Invoke-RestMethod https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/metadata.json).ReleaseTag -replace '^v' -eq '7.0.0' ? 'Happy PowerSheller' : 'A sad day'

14

u/Yevrag35 Mar 04 '20

And download it like a boss:

$latest = Invoke-RestMethod 'https://api.github.com/repos/PowerShell/PowerShell/releases/latest'

$downloadUrl = $latest.assets | Where-Object Name -like "*win-x64.msi" | Select-Object -ExpandProperty 'browser_download_url'
$fileName = Split-Path $downloadUrl -Leaf

$webClient = New-Object System.Net.WebClient
try {
    $webClient.DownloadFile($downloadUrl, "$PSScriptRoot\$fileName")
}
finally {
    $webClient.Dispose()
}

6

u/spyingwind Mar 04 '20
[Version]$ReleaseVersion = (Invoke-RestMethod https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/metadata.json).ReleaseTag -replace '^v'
if ($PSVersionTable.PSEdition -like "Core" -and $ReleaseVersion -gt $PSVersionTable.PSVersion){
    $latest = Invoke-RestMethod -Uri "https://api.github.com/repos/PowerShell/PowerShell/releases" | Where-Object {$_.tag_name -eq "v$ReleaseVersion"}
    $downloadUrl = $latest.assets | Where-Object Name -like "*win-x64.msi" | Select-Object -ExpandProperty 'browser_download_url'
    Invoke-WebRequest -Uri $downloadUrl -OutFile "$PSScriptRoot\$(Split-Path $downloadUrl -Leaf)"
}

This should check if the current version of Core is the latest release, and download it if it isn't.

5

u/chadbaldwin Mar 05 '20

Why not just use the installer that they provide?

iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -AddExplorerContextMenu -EnablePSRemoting -Quiet";

You can also use -Preview and -Daily to get different release versions.

1

u/spyingwind Mar 05 '20

Becaule iex is blocked by many AV's.

1

u/chadbaldwin Mar 05 '20

ahhh, that's interesting. I didn't know that.

I guess the work around could be...

irm https://aka.ms/install-powershell.ps1 | Out-File install-powershell.ps1
.\install-powershell.ps1 -UseMSI -AddExplorerContextMenu -EnablePSRemoting

?

1

u/spyingwind Mar 05 '20

That may work, but it effectively does the same thing, but downloads a script, which is what likely triggers AV. My bit of code doesn't download a script, but the MSI that can be authenticated with it's built in cert.

1

u/Sansred Jun 15 '20

This should be part of PowerShell, named something like Update-PowerShell

1

u/chadbaldwin Jun 15 '20

You'd think so. Usually with things like this...there's always some simple answer why they are unable to implement it. lol.

I guess until then, you can make it an alias. haha.

5

u/halbaradkenafin Mar 05 '20

Choco install pwsh or choco upgrade pwsh is even easier