Modules/businessdev.ALbuild.Containers/Private/Test-BcAdministrator.ps1

function Test-BcAdministrator {
    <#
    .SYNOPSIS
        Is the current process running elevated?
 
    .DESCRIPTION
        Changing the Docker daemon's configuration and restarting its service both require elevation.
        Checking up front turns a confusing mid-operation "Access denied" - possibly after the service
        has already been stopped - into one clear message before anything is touched.
 
        A function of its own so a test can mock it: no test suite should have to run elevated to cover
        the code paths that check for it.
 
    .OUTPUTS
        System.Boolean - $true when elevated, $false otherwise, and $false on any platform that has no
        such concept (the callers are Windows-only and check the platform separately).
    #>

    [CmdletBinding()]
    [OutputType([bool])]
    param()

    try {
        if (-not ([System.Environment]::OSVersion.Platform -eq 'Win32NT')) { return $false }
        $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
        $principal = New-Object System.Security.Principal.WindowsPrincipal($identity)
        return $principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
    }
    catch {
        Write-Verbose "Could not determine elevation: $($_.Exception.Message)"
        return $false
    }
}