Module/Administration/Enter-BCSRemoteServer.ps1

<#
.SYNOPSIS
    Connect to Remote Server
.DESCRIPTION
    Connect to remote server using BCS Powershell Module profile
.EXAMPLE
    Enter-BCSRemoteServer -server "sebcbc01.brightcom.online"
     
    Enter-BCSRemoteServer -server 'sebcbc01.brightcom.online' -userName 'myUserName' -password (Get-BCSSecureString 'myPassword')
.NOTES
    Author: Mathias Stjernfelt
    Website: http://www.brightcom.se
#>

function Enter-BCSRemoteServer {
    Param (
        [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)]
        [string]$server,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)]
        [string]$userName,
        [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)]
        [SecureString]$password
    )
    begin {}

    process {
        if ([string]::IsNullOrEmpty($userName)) {
            $moduleProfile = Get-BCSModuleProfile;            
            $userName = $moduleProfile.AzureUserName
        }

        if ([string]::IsNullOrEmpty($password)) {
            $password = ConvertTo-SecureString -String $moduleProfile.AzurePassword
        }

        Write-Host "Connecting to server $server as user $userName"

        $credential = New-Object System.Management.Automation.PSCredential -argumentList $userName, $password

        Enter-PSSession -UseSSL -ComputerName $server -Credential $credential
    }
    end {
    }
}

Export-ModuleMember -Function Enter-BCSRemoteServer