Function DownPowershell { param( [Parameter(Mandatory = $true)] [string]$Repo, [Parameter(Mandatory = $false)] [bool]$IsDebug = $false, [Parameter(Mandatory = $false)] [int]$WaitSec = 5 ) # $IsDebug = $true # $Repo = "powershell" $URL = "https://api.github.com/repos/$($Repo)/$($Repo)/releases" if ($IsDebug) { Write-Host "`$URL = $URL" -ForegroundColor Cyan } $RELEASES = irm "$URL" if ($IsDebug) { Write-Host "`$URL = $URL" -ForegroundColor Cyan Write-Host "`$RELEASES.assets = $($RELEASES.assets)" -ForegroundColor Cyan } $ASSET = $RELEASES.assets | Where-Object {($_.Name -like "*64.msi") -and ($_.Name -notlike "*arm*") } | Sort-Object $_.updated_at -Descending -Top 1 if ($IsDebug) { Write-Host "`$ASSET = $ASSET" -ForegroundColor Cyan } $browser_download_url = $ASSET.browser_download_url if ($IsDebug) { Write-Host "`$browser_download_url = $browser_download_url" -ForegroundColor Cyan } # $browser_download_url = ($RELEASES.assets | Where-Object {$_.Name -like "*x64*.exe"} | Sort-Object $_.updated_at -Descending -Top 1).browser_download_url # if ($IsDebug) { # Write-Host "`$browser_download_url = $browser_download_url" -ForegroundColor Cyan # } $FFILE = split-path -Path "$browser_download_url" -leaf $FFILE_PATH = Join-Path -Path "C:\temp" -ChildPath "$FFILE" if ($IsDebug) { Write-Host "`$FFILE = $FFILE" -ForegroundColor Cyan Write-Host "`$FFILE_PATH = $FFILE_PATH" -ForegroundColor Cyan } Write-Host "Качаю '$browser_download_url'" -ForegroundColor Cyan irm $browser_download_url -OutFile $FFILE_PATH Write-Host "Ожидаю $WAITSEC" -ForegroundColor Magenta Start-Sleep -Seconds $WAITSEC Write-Host "Запускаю '$FFILE_PATH' /S " -ForegroundColor Cyan # & "$FFILE_PATH" /S } function Main { try { Clear-Host } catch {} # DownPowershell -Repo "powershell" -IsDebug $true -WaitSec 7 DownPowershell -Repo "powershell" -IsDebug $false -WaitSec 2 } Main