Functions/Public/New-PSPuTTYSession.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function New-PSPuTTYSession {
    <#
    .Synopsis
    Creates a new PuTTY saved session.


    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [string] $Name        
      , [Parameter(Mandatory = $true)]
        [string] $Hostname
      , [Parameter(Mandatory = $true)]
        [int] $Port
      , [Parameter(Mandatory = $true)]
        [string] $ThemeName
      , [Parameter(Mandatory = $false)]
        [string] $WindowTitle
      , [Parameter(Mandatory = $true)]
        [string] $TerminalType = 'putty-256color'
      , [Parameter(Mandatory = $true)]
        [string] $UserName
    )

    $PuTTYSessionsReg = Get-PSPuTTYRegistrySessions

    ### Create a new, in-memory PuTTY saved session
    $NewSession = [PSPuTTYSession]::new()

    if ($WindowTitle) { $NewSession.WinTitle = $WindowTitle }
    if ($Port) { $NewSession.PortNumber = $Port }
    if ($TerminalType) { $NewSession.TerminalType = $TerminalType }
    
    ### Write the new PuTTY session to the registry
    $NewSession.Write()
}