Last active
March 27, 2023 18:05
-
-
Save alexgwolff/9b5343fccf80878d6fe90fafc4cb578a to your computer and use it in GitHub Desktop.
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
$ErrorActionPreference = "Stop" | |
$tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName()) | |
$null = New-Item -ItemType Directory -Path $tempDir -Force -ErrorAction SilentlyContinue | |
try { | |
$metadata = Invoke-RestMethod "https://api.github.com/repos/git-for-windows/git/releases/latest" | |
$downloadUrl = $metadata.assets.browser_download_url -match "Git-.+-64-bit.exe" | |
Write-Verbose "download package from '$downloadURL'" -Verbose | |
$packagePath = Join-Path -Path $tempDir -ChildPath "git" | |
Invoke-WebRequest -Uri $downloadURL.toString() -OutFile $packagePath | |
Write-Verbose "Performing quiet install" | |
$ArgumentList=@("/i", $packagePath, "/VERYSILENT", ` | |
"/NORESTART", ` | |
"/NOCANCEL", ` | |
"/SP-", ` | |
"/CLOSEAPPLICATIONS", ` | |
"/RESTARTAPPLICATIONS", ` | |
"/o:PathOption=CmdTools", ` | |
"/o:BashTerminalOption=ConHost", ` | |
"/o:EnableSymlinks=Enabled", ` | |
"/COMPONENTS=gitlfs") | |
$process = Start-Process msiexec -ArgumentList $ArgumentList -Wait -PassThru | |
if ($process.exitcode -ne 0) { | |
throw "Quiet install failed, please rerun install without -Quiet switch or ensure you have administrator rights" | |
} | |
$systemPath = [Environment]::GetEnvironmentVariable('PATH', [System.EnvironmentVariableTarget]::Machine) | |
$systemPath += ';' + "C:\Program Files\Git\${majorVersion}" | |
[Environment]::SetEnvironmentVariable("PATH", $systemPath, [System.EnvironmentVariableTarget]::Machine) | |
} finally { | |
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue | |
} | |
# about_update_notifications | |
# While the update check happens during the first session in a given 24-hour period, for performance reasons, | |
# the notification will only be shown on the start of subsequent sessions. | |
# Also for performance reasons, the check will not start until at least 3 seconds after the session begins. | |
[System.Environment]::SetEnvironmentVariable("POWERSHELL_UPDATECHECK", "Off", [System.EnvironmentVariableTarget]::Machine) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment