Generic/Utils.ps1
<#
.SYNOPSIS Checks if the current session has administrator rights. .DESCRIPTION Returns $true if the script is running under an elevated (Admin) session, otherwise $false. #> function Test-IsAdministrator { [OutputType([bool])] param () # Retrieve the current Windows identity and principal $currentIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent() $principal = New-Object System.Security.Principal.WindowsPrincipal($currentIdentity) # Check for the Administrator role return $principal.IsInRole([System.Security.Principal.WindowsBuiltinRole]::Administrator) } |