Private/Install/Test-PWSHYBKPIVElevated.ps1
|
function Test-PWSHYBKPIVElevated { <# .SYNOPSIS Returns whether the current PowerShell session is running elevated (as Administrator). .DESCRIPTION Wraps a WindowsPrincipal/WindowsIdentity elevation check, extracted into its own function so Install-PWSHYBKPIVTool's elevation guard can be unit tested with a mock instead of depending on the actual privilege level of the test process. .OUTPUTS Boolean. .EXAMPLE Test-PWSHYBKPIVElevated #> [CmdletBinding()] [OutputType([bool])] param() $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent() $principal = New-Object -TypeName System.Security.Principal.WindowsPrincipal -ArgumentList $identity $principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator) } |