Source/Session/Test-SessionElevation.ps1

<#
.SYNOPSIS
    Checks if the current PowerShell session has elevated privileges.
.DESCRIPTION
    Wraps the current Windows identity in a WindowsPrincipal and checks whether it belongs to the built-in Administrator role.
.EXAMPLE
    Test-SessionElevation
.INPUTS
    None.
.OUTPUTS
    [System.Boolean] True if running as Administrator, otherwise False.
#>


function Test-SessionElevation {

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

    param()

    $identity = [Security.Principal.WindowsIdentity]::GetCurrent()
    $principal = New-Object -TypeName "Security.Principal.WindowsPrincipal" -ArgumentList $identity

    return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::"Administrator")

}