Created
January 27, 2022 19:35
-
-
Save fravelgue/bb8b209162bb502d3818bf1d86f664e5 to your computer and use it in GitHub Desktop.
sshpass: Quick and dirty non-interactive ssh password auth in Powershell
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
# Add your configuration | |
$configuration = @' | |
[ | |
{ "name": "NAME", "url": "USER@HOST", "password": "PASSWORD" } | |
] | |
'@ | ConvertFrom-Json | |
$name = $args[0] | |
$url = "" | |
$psw = ""; | |
foreach($cfg in $configuration) | |
{ | |
if ($cfg.name -eq $name) | |
{ | |
$url = $cfg.url | |
$psw = $cfg.password | |
Break | |
} | |
} | |
if ($url -eq "") | |
{ | |
Write-host "Server not found" | |
exit | |
} | |
$p1 = Start-Process ssh -ArgumentList "$url" -NoNewWindow -PassThru | |
Start-Sleep 2 | |
Add-Type -AssemblyName System.Windows.Forms | |
[System.Windows.Forms.SendKeys]::SendWait($psw + '~') | |
Start-Sleep 5 | |
$p1.WaitForExit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment