Skip to content

Instantly share code, notes, and snippets.

@fravelgue
Created January 27, 2022 19:35
Show Gist options
  • Save fravelgue/bb8b209162bb502d3818bf1d86f664e5 to your computer and use it in GitHub Desktop.
Save fravelgue/bb8b209162bb502d3818bf1d86f664e5 to your computer and use it in GitHub Desktop.
sshpass: Quick and dirty non-interactive ssh password auth in Powershell
# 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