PoshCode Archive  Artifact [06d1388aa8]

Artifact 06d1388aa8c9a87a318a7345c296cbaee5d596d5f02c687ad4ea7645d5aa4886:

  • File Putty-Port-Forward-Helpe.ps1 — part of check-in [6fe3accd60] at 2018-06-10 14:17:39 on branch trunk — Two simple functions to get and set the SSH tunnels that putty will establish (user: CrazyDave size: 1395)

# encoding: ascii
# api: powershell
# title: Putty Port Forward Helpe
# 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: 6545
# x-derived-from-id: 6546
# x-archived: 2017-03-18T01:01:43
# x-published: 2017-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]
        }
    }
 }
}