Functions/Administration/Assert-CdsAdminConnected.ps1

<#
    .SYNOPSIS
    Check if current user has D365 / CDS admin role.
#>

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

        # TODO : Handle admin connection with context info
        if(-not $Global:CdsContext.IsAdminConnected)
        {
            throw "You are not connected as Admin! Please use Connect-CdsAdmin command before";           
        }
    }
    end {
        $StopWatch.Stop();
        Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch;
    }    
}

Export-ModuleMember -Function Assert-CdsAdminConnected -Alias *;