Skip to content

Instantly share code, notes, and snippets.

@natesubra
Created February 1, 2023 19:50
Show Gist options
  • Save natesubra/aae1ad18ec85b7dccd987f812cca24e3 to your computer and use it in GitHub Desktop.
Save natesubra/aae1ad18ec85b7dccd987f812cca24e3 to your computer and use it in GitHub Desktop.
SSH from windows using the gcloud CLI without being forced to use putty
# [Adapted from source:](https://superuser.com/a/1558617/91960)
# SSH from windows using the gcloud CLI without being forced to use putty
# Assumes that gcloud project defaults are set and auth is configured
function Invoke-gcloudssh {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string] $instance_name
)
# get default command as string(--dry-run)
$SrcCommand = (gcloud compute ssh "$instance_name" --dry-run) | Out-String
# remove path to putty.exe
$PuttyExe = "putty.exe"
$SrcCommand = $SrcCommand.SubString($SrcCommand.IndexOf($PuttyExe) + $PuttyExe.length)
# use ssh, remove .ppk file extension from the key name
$NewCommand = "ssh" + $SrcCommand.Replace(".ppk", "")
# run
Invoke-Expression $NewCommand
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment