20 lines
591 B
PowerShell
20 lines
591 B
PowerShell
|
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
|