Functions/Confirm-PowershellSessionHasAdministratorRole.ps1

<#
    .SYNOPSIS
    Confirms if PS session has AdministratorRole
    .DESCRIPTION
    Confirms if PS session has AdministratorRole
    .EXAMPLE
    If Confirm-PowershellSessionHasAdministratorRole { do-something }
#>


function Confirm-PowershellSessionHasAdministratorRole 
{
    PROCESS
    {

        $WindowsIdentity = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent())
        $elevated = ($WindowsIdentity.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
    
        if (-not ($elevated)) {

            return $false

        } 
        else {

            return $true

        }
    }
}

Export-ModuleMember -Function Confirm-PowershellSessionHasAdministratorRole