Created
March 31, 2016 18:48
-
-
Save tyhawkins/ca9f09c2470508905b9ed2f245671886 to your computer and use it in GitHub Desktop.
Load a directory full of PPKs
This file contains 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
# ----------------------------------------------------------------------------- | |
# PowerShell script for loading your private key files with pageant.exe | |
# Author: Martijn Burgers | |
# Find me on Twitter: http://www.twitter.com/martijnburgers | |
# ----------------------------------------------------------------------------- | |
$usage = "Usage: loadppks.ps1 [Dir|ppk file]"; | |
if ($args.Count -eq 0) { | |
write-host "No arguments supplied!" | |
write-host $usage | |
exit | |
} | |
if ($args.Count -gt 1) { | |
write-host "To many arguments supplied!" | |
write-host $usage | |
exit | |
} | |
#declare list of ppk files | |
$files = New-Object 'System.Collections.Generic.List[string]' | |
#check if arg[0] is a directory | |
$isDirectory = Test-Path $args[0] -pathType container | |
if ($isDirectory -eq $true) { | |
write-host "Searching for *.ppk in" $args[0] "and al sub directories" | |
$List = get-childitem $args[0] -recurse | where {$_.extension -eq ".ppk"} | |
foreach ($item in $List) { | |
$files.Add($item.fullname) | |
} | |
} | |
else | |
{ | |
#so must be a file then. Check if it exists. | |
if([IO.File]::Exists($args[0]) -eq $true) { | |
$files.Add($args[0]) | |
} else { | |
write-host "The given file does not exists!" | |
write-host $usage | |
exit | |
} | |
} | |
$tool = "pageant.exe" | |
write-host "Starting pageant with private keys" | |
#call pageant with ppk files | |
&$tool $files.ToArray() | |
# ----------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment