Private/Connect-SpecAzAccount.ps1

function Connect-SpecAzAccount {
    <#
    .SYNOPSIS
    Connects to Azure Account using the provided credentials.
 
    .DESCRIPTION
    The Connect-SpecAzAccount function establishes a connection to Azure Account using the specified Tenant ID and PSCredential.
 
    .PARAMETER TenantID
    The ID of the Azure tenant to connect to.
 
    .PARAMETER PSCredential
    A PSCredential object containing the client secret used for authentication.
 
    .EXAMPLE
    Connect-SpecAzAccount -TenantID "yourtenantid" -PSCredential $credential
 
    This example connects to Azure Account with the specified Tenant ID and PSCredential.
 
    .NOTES
    Return Values:
      0: Successfully connected to Azure Account.
    101: Unable to connect to Azure Account.
 
    Author: owen.heaume
    Version: 1.0
    #>


    [cmdletbinding()]

    param (
        [parameter (mandatory = $true)]
        [string]$TenantID,

        [parameter (mandatory = $true)]
        [PSCredential]$PSCredential
    )

    try {
        Write-Verbose "Attempting to connect to AzAccount"
        Connect-AzAccount -tenantid $tenantID -ServicePrincipal -Credential $psCredential -ea Stop -ev x
        Write-verbose "Connected!"
        return 0
    } catch {
        Write-Error "Unable to connect to AzAccount. The error was:$x"
        return 101
    }
}