Functions/Types/New-CdsContext.ps1

<#
    .SYNOPSIS
    Initialize new object that represent a Xrm Context.
#>

function New-CdsContext {
    [CmdletBinding()]
    [OutputType([PsObject])]
    param
    (
    )
    begin {  
        $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); 
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); 
    }    
    process {

        $hash = @{ };
        $hash["Credentials"] = [System.Management.Automation.PSCredential]::Empty;
        $hash["IsOnPremise"] = $false;
        $hash["IsOnline"] = $false;
        $hash["IsAdmin"] = $false;
        $hash["IsDevOps"] = ($null -ne $ENV:SYSTEM_COLLECTIONID);
        $hash["CurrentConnection"] = $null;
        $hash["CurrentInstance"] = $null;
        $hash["CurrentClient"] = $null;

        $object = New-Object PsObject -Property $hash;
        $object;
    }
    end {
        $StopWatch.Stop();
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch;
    }
}

Export-ModuleMember -Function New-CdsContext -Alias *;