ps/Modules/Alkami.PowerShell.Common/Public/Test-IsAdmin.ps1

20 lines
591 B
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function Test-IsAdmin {
<#
.SYNOPSIS
Returns true if the current user is an administrator.
#>
[CmdletBinding()]
Param()
try {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent();
$principal = New-Object Security.Principal.WindowsPrincipal -ArgumentList $identity;
return $principal.IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator );
}
catch {
throw "Failed to determine if the current user has elevated privileges. The error was: '{0}'." -f $_;
}
}
Set-Alias IsAdmin Test-IsAdmin -Force -Scope:Global