PoshCode Archive  Artifact [79ae9f201f]

Artifact 79ae9f201fb4f0812e239d340770a0317ec5b141714f2049059b2964dfe9f10f:

  • File Putty-SSH-Tunnels.ps1 — part of check-in [f6d6073a05] at 2018-06-10 14:17:41 on branch trunk — Two simple functions to get and set the SSH tunnels that putty will establish (user: CrazyDave size: 1361)

# 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]
        }
    }
 }
}