Created
February 1, 2023 19:50
-
-
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
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
# [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