Public/func_Remove-SSHServer.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
function Remove-SSHServer {
    [CmdletBinding()]
    param (
        [Parameter(Position = 0, Mandatory = $true)][string]$Name
    )
    [Collections.Generic.List[SSHServer]]$sshServers = Get-SSHServersFile
    $toedit = $sshServers | Where-Object Name -eq $Name
    if($null -eq $toedit)
    {
        Throw New-Object System.NullReferenceException("SSH Server not found")
    }

    $toedit | Out-Default

    $key = Read-Host -Prompt "Are you sure to delete this entry ?[Y/N]"
    if($key.ToUpperInvariant() -eq "Y")
    {
        $sshServers.Remove($toedit) | Out-Null
        Set-SSHServersFile -SSHServers $sshServers
    }
    else {
        Write-Host "Operation aborted" -ForegroundColor Yellow
    }
}