-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck-perms.ps1
60 lines (50 loc) · 1.6 KB
/
check-perms.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
param (
$user = $(throw "-user is a required option. Use DOMAIN\username formatting.")
)
Import-module activedirectory
Function Check-ADUserPermission(
[System.DirectoryServices.DirectoryEntry]$entry,
[string]$user,
[string]$permission)
{
$dse = [ADSI]"LDAP://Rootdse"
$ext = [ADSI]("LDAP://CN=Extended-Rights," + $dse.ConfigurationNamingContext)
$right = $ext.psbase.Children |
? { $_.DisplayName -eq $permission }
if($right -ne $null)
{
$perms = $entry.psbase.ObjectSecurity.Access |
? { $_.IdentityReference -eq $user } |
? { $_.ObjectType -eq [GUID]$right.RightsGuid.Value }
return ($perms -ne $null)
}
else
{
Write-Warning "Permission '$permission' not found."
return $false
}
}
Function Check-ReplicateChanges([string]$userName)
{
# Globals
$replicationPermissionName = "Replicating Directory Changes"
# Main()
$dse = [ADSI]"LDAP://Rootdse"
$entries = @(
[ADSI]("LDAP://" + $dse.defaultNamingContext) #, [ADSI]("LDAP://" + $dse.configurationNamingContext)
);
Write-Host " User '$userName': "
foreach($entry in $entries)
{
$result = Check-ADUserPermission $entry $userName $replicationPermissionName
if($result)
{
Write-Host " has '$replicationPermissionName' permissions on '$($entry.distinguishedName)'" `
}
else
{
Write-Host " does NOT have '$replicationPermissionName' permissions on '$($entry.distinguishedName)'" `
}
}
}
Check-ReplicateChanges $user