Created
August 28, 2017 14:10
-
-
Save dontpaniclabsgists/45bdf34383eb5ab5669d2981e1cd92fe to your computer and use it in GitHub Desktop.
posh_git_2
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
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