# encoding: ascii
# api: powershell
# title: Putty SSH Tunnels
# description: Two simple functions to get and set the SSH tunnels that putty will establish
# version: 0.1
# type: function
# author: CrazyDave
# license: CC0
# x-poshcode-id: 6546
# x-archived: 2016-10-29T00:01:06
# x-published: 2016-10-04T18:39:00
#
#
function AddPortForward {
param(
[String] $Connection,
[UInt16] $SrcPort,
[String] $DstHost,
[UInt16] $DstPort
)
$baseSessionFolder = 'Software\SimonTatham\PuTTY\Sessions'
$key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($baseSessionFolder + "\" + $Connection, $true)
$currentValue = $key.GetValue("PortForwardings")
$newValue = $currentValue + "L" + $SrcPort + "=" + $DstHost + ":" + $DstPort + ","
$key.SetValue("PortForwardings", $newValue, [Microsoft.Win32.RegistryValueKind]::String)
}
function GetPortForwards {
$baseSessionFolder = 'HKCU:\Software\SimonTatham\PuTTY\Sessions'
gci $baseSessionFolder | % {
$key = $_
$key.GetValue("PortForwardings").Split(',', [System.StringSplitOptions]::RemoveEmptyEntries) | % {
$parts = $_.Split('=')
New-Object PSObject -Property @{
Connection = $key.PSChildName
SRC = $parts[0]
DST = $parts[1]
}
}
}
}