Functions/Test-Administrator.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# ===========================================================================
# Test-Administrator.ps1 --------------------------------------------------
# ===========================================================================

# function ----------------------------------------------------------------
# ---------------------------------------------------------------------------
Function Test-Administrator {

    <#
    .SYNOPSIS
        Test whether current powershell session is run by administrator.
 
    .DESCRIPTION
        Test whether current powershell session is run by administrator. Return true, if powershell session is run by administrator.
 
    .EXAMPLE
        PS C:\> Test-Administrator
        False
 
        -----------
        Description
        Return false, if powershell session is not run by administrator.
 
 
    .INPUTS
        None.
 
    .OUTPUTS
        Bool. Return true, if powershell session is run by administrator.
    #>


    [CmdletBinding(PositionalBinding)]
    
    [OutputType([Bool])]

    Param()

    Process {

        return (New-Object Security.Principal.WindowsPrincipal ([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)

    }
}