1
+ try
2
+ {
3
+ $importLocalizedDataParams = @ {
4
+ BaseDirectory = $PSScriptRoot
5
+ UICulture = $PSUICulture
6
+ FileName = ' AccessControlResourceHelper.strings.psd1'
7
+ ErrorAction = ' Stop'
8
+ }
9
+ $script :localizedData = Import-LocalizedData @importLocalizedDataParams
10
+ }
11
+ catch
12
+ {
13
+ $importLocalizedDataParams.UICulture = ' en-US'
14
+ try
15
+ {
16
+ $script :localizedData = Import-LocalizedData @importLocalizedDataParams
17
+ }
18
+ catch
19
+ {
20
+ throw ' Unable to load localized data'
21
+ }
22
+ }
23
+
1
24
function Resolve-Identity
2
25
{
3
26
<#
4
27
. SYNOPSIS
5
- Resolves the principal name SID
28
+ Resolves the principal name SID
6
29
7
30
. PARAMETER Identity
8
31
Specifies the identity of the principal.
@@ -24,7 +47,7 @@ function Resolve-Identity
24
47
25
48
$tryNTService = $false
26
49
27
- try
50
+ try
28
51
{
29
52
if ($Identity -match ' ^S-\d-(\d+-){1,14}\d+$' )
30
53
{
@@ -58,20 +81,20 @@ function Resolve-Identity
58
81
[System.Security.Principal.NTAccount ]$Id = " NT Service\" + $Identity
59
82
$SID = $Id.Translate ([System.Security.Principal.SecurityIdentifier ])
60
83
$NTAccount = $SID.Translate ([System.Security.Principal.NTAccount ])
61
-
84
+
62
85
$Principal = [PSCustomObject ]@ {
63
86
Name = $NTAccount.Value
64
87
SID = $SID.Value
65
88
}
66
-
89
+
67
90
return $Principal
68
91
}
69
92
catch
70
93
{
71
94
$ErrorMessage = " Could not resolve identity '{0}': '{1}'." -f $Identity , $_.Exception.Message
72
95
Write-Error - Exception $_.Exception - Message $ErrorMessage
73
96
}
74
- }
97
+ }
75
98
}
76
99
}
77
100
@@ -80,7 +103,7 @@ function Resolve-Identity
80
103
Takes identity name and translates to SID
81
104
82
105
. PARAMETER IdentityReference
83
- System.Security.Principal.NTAccount object
106
+ System.Security.Principal.NTAccount object
84
107
85
108
. EXAMPLE
86
109
$IdentityReference = (Get-Acl -Path C:\temp).access[0].IdentityReference
@@ -96,27 +119,27 @@ function ConvertTo-SID
96
119
$IdentityReference
97
120
)
98
121
99
- try
122
+ try
100
123
{
101
124
If ($IdentityReference.Contains (" \" ))
102
125
{
103
126
$IdentityReference = $IdentityReference.split (' \' )[1 ]
104
127
}
105
-
128
+
106
129
[System.Security.Principal.NTAccount ]$PrinicipalName = $IdentityReference
107
130
$SID = $PrinicipalName.Translate ([System.Security.Principal.SecurityIdentifier ])
108
-
131
+
109
132
Return $SID
110
133
}
111
- catch
134
+ catch
112
135
{
113
136
# Probably NT Service which needs domain portion to translate without error
114
137
[System.Security.Principal.NTAccount ]$Id = " NT Service\" + $IdentityReference
115
138
$SID = $Id.Translate ([System.Security.Principal.SecurityIdentifier ])
116
139
117
140
return $SID
118
141
}
119
-
142
+
120
143
}
121
144
122
145
function Assert-Module
@@ -136,33 +159,33 @@ function Assert-Module
136
159
$errorMessage = $localizedString.RoleNotFoundError -f $ModuleName ;
137
160
ThrowInvalidOperationError - ErrorId $errorId - ErrorMessage $errorMessage ;
138
161
}
139
- }
162
+ }
140
163
141
164
function Get-DelegationRightsGuid
142
165
{
143
- Param
166
+ Param
144
167
(
145
168
[Parameter ()]
146
169
[string ]
147
170
$ObjectName
148
171
)
149
172
150
- if ($ObjectName )
173
+ if ($ObjectName )
151
174
{
152
175
# Create a hashtable to store the GUID value of each schemaGuids and rightsGuids
153
176
$guidmap = @ {}
154
177
$rootdse = Get-ADRootDSE
155
- Get-ADObject - SearchBase ($rootdse.SchemaNamingContext ) - LDAPFilter " (schemaidguid=*)" - Properties Name, schemaIDGUID |
156
- Foreach-Object - Process { $guidmap [$_.Name ] = [System.GUID ]$_.schemaIDGUID }
178
+ Get-ADObject - SearchBase ($rootdse.SchemaNamingContext ) - LDAPFilter " (schemaidguid=*)" - Properties Name, schemaIDGUID |
179
+ Foreach-Object - Process {$guidmap [$_.Name ] = [System.GUID ]$_.schemaIDGUID }
157
180
158
- Get-ADObject - SearchBase ($rootdse.ConfigurationNamingContext ) - LDAPFilter " (&(objectclass=controlAccessRight)(rightsguid=*))" - Properties Name, rightsGuid |
159
- Foreach-Object - Process { $guidmap [$_.Name ] = [System.GUID ]$_.rightsGuid }
181
+ Get-ADObject - SearchBase ($rootdse.ConfigurationNamingContext ) - LDAPFilter " (&(objectclass=controlAccessRight)(rightsguid=*))" - Properties Name, rightsGuid |
182
+ Foreach-Object - Process {$guidmap [$_.Name ] = [System.GUID ]$_.rightsGuid }
160
183
161
184
return [system.guid ]$guidmap [$ObjectName ]
162
185
}
163
186
else
164
187
{
165
- return [system.guid ]" 00000000-0000-0000-0000-000000000000"
188
+ return [system.guid ]' 00000000-0000-0000-0000-000000000000'
166
189
}
167
190
}
168
191
@@ -175,22 +198,84 @@ function Get-SchemaObjectName
175
198
$SchemaIdGuid
176
199
)
177
200
178
- if ($SchemaIdGuid )
201
+ if ($SchemaIdGuid -and ( $SchemaIdGuid .Guid -ne ' 00000000-0000-0000-0000-000000000000 ' ) )
179
202
{
180
203
$guidmap = @ {}
181
204
$rootdse = Get-ADRootDSE
182
- Get-ADObject - SearchBase ($rootdse.SchemaNamingContext ) - LDAPFilter " (schemaidguid=*)" - Properties Name, schemaIDGUID |
183
- Foreach-Object - Process { $guidmap [$_.Name ] = [System.GUID ]$_.schemaIDGUID }
205
+ Get-ADObject - SearchBase ($rootdse.SchemaNamingContext ) - LDAPFilter " (schemaidguid=*)" - Properties Name, schemaIDGUID |
206
+ Foreach-Object - Process {$guidmap [$_.Name ] = [System.GUID ]$_.schemaIDGUID }
184
207
185
- Get-ADObject - SearchBase ($rootdse.ConfigurationNamingContext ) - LDAPFilter " (&(objectclass=controlAccessRight)(rightsguid=*))" - Properties Name, rightsGuid |
186
- Foreach-Object - Process { $guidmap [$_.Name ] = [System.GUID ]$_.rightsGuid }
208
+ Get-ADObject - SearchBase ($rootdse.ConfigurationNamingContext ) - LDAPFilter " (&(objectclass=controlAccessRight)(rightsguid=*))" - Properties Name, rightsGuid |
209
+ Foreach-Object - Process {$guidmap [$_.Name ] = [System.GUID ]$_.rightsGuid }
187
210
188
211
# This is to address the edge case where one guid resolves to multiple names ex. f3a64788-5306-11d1-a9c5-0000f80367c1 resolves to Service-Principal-Name,Validated-SPN
189
- $names = ( $guidmap.GetEnumerator () | Where-Object - FilterScript { $_.Value -eq $SchemaIdGuid } ).Name
212
+ $names = ($guidmap.GetEnumerator () | Where-Object - FilterScript {$_.Value -eq $SchemaIdGuid } ).Name
190
213
return $names -join ' ,'
191
214
}
192
215
else
193
216
{
194
- return " none"
217
+ return ' None'
218
+ }
219
+ }
220
+
221
+ function Write-CustomVerboseMessage
222
+ {
223
+ param
224
+ (
225
+ [Parameter (Mandatory = $true )]
226
+ [System.String ]
227
+ $Action ,
228
+
229
+ [Parameter (Mandatory = $true )]
230
+ [System.String ]
231
+ $Path ,
232
+
233
+ [Parameter (Mandatory = $true )]
234
+ [ValidateScript ({
235
+ $_ -is [System.DirectoryServices.ActiveDirectoryAccessRule ] -or
236
+ $_ -is [System.DirectoryServices.ActiveDirectoryAuditRule ] -or
237
+ $_ -is [System.Security.AccessControl.FileSystemAccessRule ]
238
+ })]
239
+ $Rule
240
+ )
241
+
242
+ $properties = [ordered ]@ {
243
+ IdentityReference = $Rule.IdentityReference
244
+ }
245
+
246
+ switch ($Rule.GetType ().Name)
247
+ {
248
+ ' ActiveDirectoryAccessRule'
249
+ {
250
+ # future expansion
251
+ break
252
+ }
253
+
254
+ ' ActiveDirectoryAuditRule'
255
+ {
256
+ $properties.Add (' ActiveDirectoryRights' , $Rule.ActiveDirectoryRights )
257
+ $properties.Add (' AuditFlags' , $Rule.AuditFlags )
258
+ $properties.Add (' ObjectType' , $ (Get-SchemaObjectName - SchemaIdGuid $Rule.ObjectType ))
259
+ $properties.Add (' InheritanceType' , $Rule.InheritanceType )
260
+ $properties.Add (' InheritedObjectType' , $ (Get-SchemaObjectName - SchemaIdGuid $Rule.InheritedObjectType ))
261
+ break
262
+ }
263
+
264
+ ' FileSystemAccessRule'
265
+ {
266
+ $properties.Add (' AccessControlType' , $Rule.AccessControlType )
267
+ $properties.Add (' FileSystemRights' , $Rule.FileSystemRights )
268
+ $properties.Add (' InheritanceFlags' , $Rule.InheritanceFlags )
269
+ $properties.Add (' PropagationFlags' , $Rule.PropagationFlags )
270
+ break
271
+ }
272
+ }
273
+
274
+ Write-Verbose - Message $localizedData [$Action ] - Verbose
275
+ Write-Verbose - Message ($localizedData.Path -f $Path ) - Verbose
276
+
277
+ foreach ($property in $properties.Keys -as [array ])
278
+ {
279
+ Write-Verbose - Message ($localizedData [$property ] -f $properties [$property ]) - Verbose
195
280
}
196
281
}
0 commit comments