private/Test-IsAdministrator.ps1
|
function Test-IsAdministrator { <# .SYNOPSIS Tests whether the current Windows identity has Administrator privileges .DESCRIPTION Creates a Windows principal for the current identity and tests membership in the built-in Administrator role. Returns the result of the role membership test. .EXAMPLE PS> Test-IsAdministrator Tests whether the current process is running with Administrator privileges. .INPUTS None. This function does not accept pipeline input. .OUTPUTS System.Boolean. Returns $true when the current identity is in the Administrator role; otherwise, returns $false. .NOTES Author: David Segura Company: Recast Software Version: 1.0.0 Date: 2026-08-28 Requires Windows security principal APIs. #> [OutputType([bool])] param () $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent() $principal = [System.Security.Principal.WindowsPrincipal]::new($identity) return $principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator) } |