(tested on Windows PowerShell 5+ & 7+)
If ($PWD -match '\b(System32|Windows|Program\sFile.*$|C:\\)') { Push-Location (Join-Path $Home 'Downloads') }; Invoke-WebRequest https://raw.githubusercontent.com/HerbM/WindowsPowerShell/master/Scripts/Get-WindowsGit.ps1 -out Get-WindowsGit.ps1; ./Get-WindowsGit -install; cd $Home\Documents; & 'c:\Program Files\Git\bin\git' clone https://github.com/HerbM/WindowsPowerShell
<#.SynopsisGetgit forWindows and clone WindowsPowerShelltoprofile directory.Notes#INITIALgit clone repo fromGitHub#Installgit(source below)--where.exe git##will find gitif onpathGet-WindowsGit.ps1 ##will download it(to$Home\Downloads by default)# Find projectonGitHub --search"Herb Martin"USERSWindowsPowerShell# Clone (green button) copyURL,whichis alsoonnextline:#https://github.com/HerbM/WindowsPowerShellgitremote -v#willshow:#originhttps://github.com/HerbM/WindowsPowerShell#originhttps://github.com/HerbM/WindowsPowerShell# Eventuallyyouwillneed a decent.gitprofile,usuallyin$Home#$Home/.gitprofile# but`$Env:Home maypointsomewhere else:[$($Env:Home)]md (Split-Path)$Profile -ea 0 #OR:md $Home\Documents\WindowsPowerShell-ea 0 cd (Split-Path)$Profile -ea 0 #OR: cd $Home\Documents\WindowsPowerShellgit clone https://github.com/HerbM/WindowsPowerShell.# DOTIF inProfile directory#Subsequentgitmerge: cd (Split-Path)$Profile #OR: cd $ProfileDirectorygitstatus#git commit-a -m"Save my changes"#gitstashpush FILENAME #-a save or commityour changesgitpull# allyouneed if you cloned# C:\Program Files\Git\cmd\git.exe #maybe# C:\ProgramData\chocolatey\bin\notepad++.exe#Isgitinstalled?URL?# C:\ProgramData\chocolatey\bin\notepad++.exe#What'sthe repoURL?(https://github.com/HerbM/WindowsPowerShell buthowto find it)gitremote -v#willshow:#HerbProfile https://github.com/HerbM/WindowsPowerShell#HerbProfile https://github.com/HerbM/WindowsPowerShell#where.exe git#to find git,'Where' aliaspointsto'Where-Object',sowhere.exe ishidden by default#>
[CmdLetBinding(SupportsShouldProcess=$true,ConfirmImpact='Low')]
param( [Alias('Url','Link')] [string]$uri='https://git-scm.com/download/win', # Windows Git page [Alias('Directory')][string[]]$Path="$Home\Downloads", # downloaded file to path [Alias('GitInstall')][switch]$Install, [Alias('bit32','b32','old')][switch]$Bits32)$VersionPattern=If($bits32) { 'git-.*-32-bit.exe' } else { 'git-.*-64-bit.exe' }
[Net.ServicePointManager]::SecurityProtocol="tls12,tls11,tls"<#$VimHelp=@'# By defaultGitrunsVimto edit commits automatically#Howto ExitVim(with&withoutsaving changes)#:w-write (save)the file, but don't exit#:w!sudotee %-write outthe current file usingsudo#:wqor:xorZZ-write (save) and quit#:q-quit(failsif there are unsaved changes)#:q!orZQ-quit and throw awayunsaved changes#:wqa -write (save) and quiton alltabs##https://vim.rtorr.com/#http://www.viemu.com/vi-vim-cheat-sheet.gif#http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html#https://github.com/hackjutsu/vim-cheatsheetText,you canpaste orgit#http://vimsheet.com/#http://vimsheet.com/advanced.html#"The bestpossible resource onvimisthe bookPracticalVim.#https://www.amazon.com/Practical-Vim-Thought-Pragmatic-Programmers/dp/1934356980'@#<<<<<<<<<<<<<<< doNOTINDENT,must be a leftmarginwrite-host$VimHelp-fore yellow-back darkblue#>If($PWD -match '\b(System32|Windows|Program\sFile.*)$') {
$Local:OldDir=$PwdWrite-Warning"Changingoutof$PWDtopreventloadingthisaccidentallyinabadplace"Write-Warning""Push-LocationJoin-Path$Home'Downloads'Write-Warning"Toreturnto$OldDirtype:popd"
}
Write-Verbose"Uri:$Uri"$Page=Invoke-WebRequest-Uri$Uri-UseBasicParsing-verbose:$false#getthewebpage$InstallerUri=($page.links | where outerhtml -match $VersionPattern | Select -first 1 *).href#downloadlinklatest64-bitversionWrite-Verbose"InstallerUri:$InstallerUri"$FileName=Split-Path$InstallerUri-leaf#splitoutthefilenameWrite-Verbose"Filename:$filename"$InstallerlPath=Join-Path-Path$path-ChildPath$filename#constructafilepathforthedownloadWrite-Verbose"Downloadsavepath:$InstallerlPath"if($PSCmdlet.ShouldProcess("$InstallerUri", "Saving: $InstallerlPath`n")) {
Invoke-WebRequest-uri$InstallerUri-OutFile$InstallerlPath-UseBasicParsing-verbose:$false#downloadfile
}
Get-item$InstallerlPath|ForEach { "$($_.length)$($_.lastwritetime)$($_.fullname)" }
#$PSVersionTable.PSVersion-gt [Version]'6.0'if(Test-Path $InstallerlPath) {
If($Install) {
Write-Warning"Runninggitinstall:$InstallerlPath/verysilent"&$InstallerlPath/verysilentIf(!(Get-Command git -CommandType Application -ea Ignore) -and ($Env:Path -notmatch 'C:.Program Files.*\bGit.cmd')) {
If($Bits32) { $Env:Path+=';C:\ProgramFiles\Git\cmd' }
Else { $Env:Path+=';C:\ProgramFiles(x86)\Git\cmd' }
}
}
#$InstallerlPath/verysilent#ToinstallGit"Write-Host(' ' * 72)-forewhite-backdarkcyan$Instructions=@"#RUNTHESECOMMANDSIFyoudon'talreadyhaveaPowerShellprofile:`$Env:Path+=';C:\ProgramFiles\Git\cmd'#orrestartPowerShellcd`$Home\Documents-eaignore#ifyoudon'thaveaProfile#WindowsPowerShellthrough5.xgitclonehttps://github.com/HerbM/WindowsPowerShellWindowsPowerShell#PowerShell7+gitclonehttps://github.com/HerbM/WindowsPowerShellPowerShell#Toloadnewprofilethefirsttime,orreloadlater.`$Profile#orrestartPowerShellconsoletoautoloadprofile"@Write-Host$Instructions-forewhite-backdarkblueWrite-Host(' ' * 72)-forewhite-backdarkcyanWrite-Host''
} else {
"DownloadFAILEDto$InstallerlPath"
}
<##https://www.ssllabs.com/ssltest/index.html#https://www.ssllabs.com/ssltest/analyze.html?d=git-scm.com&latest#https://www.ssllabs.com/ssltest/analyze.html?d=git-scm.com&s=104.20.12.91&latest#>