Sample/Find-Duplicates/common/connect.ps1

# ------------------------------------------------------------------
# Lenovo Copyright
#
# (C) Copyright Lenovo 2024 - present.
#
# LIMITED AND RESTRICTED RIGHTS NOTICE:
# If data or software is delivered pursuant a General Services
# Administration (GSA) contract, use, reproduction, or disclosure
# is subject to restrictions set forth in Contract No. GS-35F-05925.
# ------------------------------------------------------------------

. $PSScriptRoot\ServersConfigData.ps1

function LXCAConnect()
{
    param (
        [Parameter(Mandatory = $true)]
        [string] $DataPath
    )

    $connections = @()
    $data = [ConfigData]::new()
    $lxcaDatas = $data.GetLXCAData($DataPath)
    foreach ($lxca in $lxcaDatas)
    {
        $secPassword = ReadPassword -Host $lxca.ip -Username $lxca.userName
        $Cred = New-Object System.Management.Automation.PSCredential($lxca.userName, $secPassword)
        $con = Connect-LXCA -Host $lxca.ip -Credential $Cred -Port $lxca.port -SkipCertificateCheck
        $connections += $con
    }
    return $connections
}

function ReadPassword()
{
    param (
        [Parameter(Mandatory = $true)]
        $Host,
        [Parameter(Mandatory = $true)]
        $Username
    )
    $secureUserInput = Read-Host "Please enter $Username password for $Host" -AsSecureString
    $encryptedInput = ConvertFrom-SecureString -String $SecureUserInput
    return (ConvertTo-SecureString -String $EncryptedInput)
}


function LXCADisconnect()
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        $Connections
    )
    foreach ($con in $Connections)
    {
        Disconnect-LXCA -Connection $con
    }
}
#EOF