Functions/Open-SshToGateway.ps1


function Open-SshToGateway {
    [CmdletBinding()]
    param (
        #[Parameter(Mandatory)] [string] $ParameterName
    )

    $GwVm = "JT-Gateway2"

    switch ($env:COMPUTERNAME) {
        "14X1134" {
            $VMSwitch = "WAN_NAT"
        }
        "ZOLDER" {
            $VMSwitch = "Ext"
        }
        "ZOLDER2" {
            $VMSwitch = "Ext"
        }
    }

    $GwVmSwtich = Get-VM $GwVm | Get-VMNetworkAdapter | Where-Object SwitchName -EQ $VMSwitch

    $GwVmSwtich.IPAddresses | ForEach-Object {
        # if($_ -match "....") {
        if ($_ -like "*.*.*.*") {
            $GwIP = $_
            Write-Verbose $GwIP
        }
    }

    # $GwIP

    if ($GwIP) {
        ssh root@$GwIP
    }

}