Skip to content

Instantly share code, notes, and snippets.

@bdwyertech
Last active January 20, 2018 18:49
Show Gist options
  • Save bdwyertech/88b2f78ff7f4a197412b69e980e71a91 to your computer and use it in GitHub Desktop.
Save bdwyertech/88b2f78ff7f4a197412b69e980e71a91 to your computer and use it in GitHub Desktop.
Windows - OpenSSH & GIT
# Filename: Set-GIT_SSH_COMMAND.ps1
# Brian Dwyer - 1/20/18
# GIT_SSH_COMMAND = '"C:\Program Files\OpenSSH-Win64\ssh.exe"'
# ***USAGE***
# To Setup the GIT_SSH_COMMAND Variable
# ./Set-GIT_SSH_COMMAND.ps1 set
# To Remove the GIT_SSH_COMMAND Variable
# ./Set-GIT_SSH_COMMAND.ps1 unset
# System-Wide Environmental Variables
$System_Vars='HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
# User-Specific Environmental Variables
$User_Vars='HKCU:\Environment'
# Check if SSH is installed
If (!$env:Path.Contains('OpenSSH'))
{
echo ""
echo "/======| Error: OpenSSH does not seem to be installed. |=====\"
echo ""
pause
exit
}
# Get SSH Installation Directory
$ssh_DIR = $env:Path.Split(';') -like "*OpenSSH*" | Out-String -Stream
# Registry Property Key/Value
$Reg_Key='GIT_SSH_COMMAND'
$Reg_Value="'$ssh_DIR\ssh.exe'"
# Setup
If ( $args[0] -eq 'set' )
{
echo "/======| Setting up Registry Key... |=====\"
Set-ItemProperty $User_Vars -Name $Reg_Key -Value $Reg_Value
pause
}
Elseif ( $args[0] -eq 'unset' )
{
echo "/======| Removing Registry Key... |=====\"
Remove-ItemProperty $User_Vars -Name $Reg_Key
pause
}
Else
{
echo '-------------------------------------------------'
echo "|*|-Set GIT_SSH_COMMAND Environmental Variable-|*|"
echo '-------------------------------------------------'
echo "| Use 'set' or 'unset' to control script |"
echo '-------------------------------------------------'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment