Skip to content

Instantly share code, notes, and snippets.

@dontpaniclabsgists
Created August 28, 2017 14:10
Show Gist options
  • Save dontpaniclabsgists/45bdf34383eb5ab5669d2981e1cd92fe to your computer and use it in GitHub Desktop.
Save dontpaniclabsgists/45bdf34383eb5ab5669d2981e1cd92fe to your computer and use it in GitHub Desktop.
posh_git_2
Import-Module posh-git
Start-SshAgent -Quiet
$loadedFiles = Add-SshKey -l
$existingFiles = Get-ChildItem "~/.ssh/"
$fileRegEx = new-object System.Text.RegularExpressions.Regex ('^id_rsa_[^\.]+$', [System.Text.RegularExpressions.RegexOptions]::MultiLine)
ForEach($file in $existingFiles){
If($fileRegEx.IsMatch($file.Name)){
$regExText = "(\\|/)\.ssh(\\|/)$($file.Name) \(RSA\)\s*$"
$loadedRegEx = new-object System.Text.RegularExpressions.Regex ($regExText, [System.Text.RegularExpressions.RegexOptions]::MultiLine)
$found=$False
ForEach($loadedFile in $loadedFiles){
If($loadedRegEx.IsMatch($loadedFile)){
$found=$True
}
}
if(-Not ($found)){
$result = Read-Host -Prompt "Do you wish to use $($file.Name)? (Y|N)"
if($result -eq "y"){
Add-SshKey $file.FullName;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment