functions/Get-CurrentUser.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

Function Get-CurrentUser{
    return `
        [Security.Principal.WindowsPrincipal]`
        [Security.Principal.WindowsIdentity]::GetCurrent()
}

Function Test-UserGroupMembership{
    param(
        [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)]
        [Security.Principal.WindowsPrincipal]
        [Security.Principal.WindowsIdentity]
        $User,
        [Parameter(ValueFromPipelineByPropertyName)]
        [string] $Group
    )
    process{
        return $User.IsInRole($Group)
    }
}

Export-ModuleMember -Function Get-CurrentUser, Test-UserGroupMembership