Skip to content

Instantly share code, notes, and snippets.

@aetos382
Created April 17, 2020 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aetos382/0c6b0a6b5ca115ff8dde6b637f405f84 to your computer and use it in GitHub Desktop.
Save aetos382/0c6b0a6b5ca115ff8dde6b637f405f84 to your computer and use it in GitHub Desktop.
function Start-AwsPortForwarding {
param(
[Parameter(Mandatory, Position = 0)]
[string] $TargetInstanceId,
[Parameter(Mandatory)]
[int] $RemotePort,
[Parameter(Mandatory)]
[int] $LocalPort,
[string] $ProfileName = 'default')
$paramJson = @{ portNumber = @([string] $RemotePort); localPortNumber = @([string] $LocalPort) } | ConvertTo-Json -Compress
$paramJson = $paramJson -replace '"', '\"'
aws ssm start-session --document-name AWS-StartPortForwardingSession --parameter $paramJson --target $TargetInstanceId --profile $ProfileName
}
function Start-AwsPortForwardingForRemoteDesktop {
param(
[Parameter(Mandatory, Position = 0)]
[string] $TargetInstanceId,
[int] $RemotePort = 3389,
[int] $LocalPort = 33890,
[string] $ProfileName = 'default')
$params = @{
TargetInstanceId = $TargetInstanceId
RemotePort = $RemotePort
LocalPort = $LocalPort
ProfileName = $ProfileName
}
Start-AwsPortForwarding @params
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment