nemesis
Goto Top

NTFS Berechtigungstool mit Active Directory Gruppen Erstellung

Hallo zusammen,

Ich suche ein Skript oder Tool welches :
a) durch die angebe eine Pfades im Active Directory eine Gruppe erzeugen kann
b) diese Gruppe im NTFS Filesystem berechtigt
[Bis hier hin ja nicht schwer]
Und dann aber wenn es sich um die x te Untereben handelt
a) die entsprechenden List Gruppen Pro unterordnete im AD erzeugt und diese Berechtigt mit "Nur dieser Ordner"
b) den Baum durch verschachteln aufbaut
c) prüft ob es bereits eine Listgruppe gibt und die darunter dann hinzufügt.

Beispiel Pfad:
\\Server\Freigabe\Ebene1\Ebene2\Ebene3

Beispiel Gruppen:
DIR_Freigabe_Ebene1_Ebene2_Ebene3_modify

DIR_Freigabe_Ebene1_Ebene2_list
DIR_Freigabe_Ebene1_list

DIR_Freigabe_Eben1_Ebene2_Ebene3_modify
ist in der
DIR_Freigabe_Ebene1_Ebene2_List
ist in der
DIR_Freigabe_Ebene1_List
Verschachtelt
(Nested Groups)

Vielen Dank

Mit freundlichen Grüßen Nemesis

Content-ID: 1126973059

Url: https://administrator.de/forum/ntfs-berechtigungstool-mit-active-directory-gruppen-erstellung-1126973059.html

Ausgedruckt am: 02.04.2025 um 01:04 Uhr

SlainteMhath
SlainteMhath 06.08.2021 um 07:51:40 Uhr
Goto Top
Moin,

das ist mit Powershell ja nicht das Problem. Hast du schon eine Script "Rumpf"?

lg,
Slainte
Festus94
Festus94 06.08.2021 um 08:04:47 Uhr
Goto Top
Hi @nEmEsIs,

grundsätzlich würde ich das auch mit PowerShell realisieren. Aber bevor du das umsetzt, kann ich dir nur nahelegen, zu überlegen, ob du das wirklich willst, da diese komplexen Strukturen irgendwann niemand mehr durchblickt.

Wir sind vor langer Zeit dazu übergegangen, dass es nur noch auf der obersten Ebene im File Service pro Ordner eine Read- und eine Modify-Grupe gibt. Dann hatteman entweder Zugriff auf alles in diesem Ordner oder eben nicht. Aber es wird nicht tiefer als auf Ebee 1 berechtigt. Neue Berechtigung = neuer Ordner auf Ebene 1.

Das hat die Sache deutlich erleichtert, transparenter gemacht und Problemen vorgebeugt. Nur mal so als Idee. face-smile

Viele Grüße

Festus94
colinardo
colinardo 06.08.2021 aktualisiert um 14:36:39 Uhr
Goto Top
Servus Nemesis,
ohne das Konstrukt jetzt in Frage zu stellen, probier mal das als Grundgerüst (Achtung: Code aus Langeweile ungetestet frei aus dem Gedächtnis in der Bahn mit 10+ Internet-Unterbrechungen geschrieben, somit ohne Gewähr auf Leib und Leben face-smile ach was bin ich froh wenn ich die deutsche Grenze passiert habe, dann sind die Unterbrechungen wohl Vergangenheit.)

Script dann folgendermaßen mit dem Pfad als Parameter starten
.\script.ps1 -path '\\SERVER\Share\Level1\Level2\Level3'

Script
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
61
62
63
param(
    [Parameter(mandatory=$true)][string]$path
)
$ErrorActionPreference = "Stop"  

# check path
if (Test-Path $path){
    # get path as object
    $current = Get-Item $path
}else{
    # create directory if  it does not exist
    $current = md $path -Force
}
# start group mode
$mode = "modify"  
# loop until root path of share equals current processed directory level
while($current.FullName -ne $current.Root.FullName){
    write-host "Processing folder $($current.FullName) ... " -F Green -NoNewline  
    # construct group name
    $grp_name = "DIR_" + (($current.Fullname -replace '^\\\\[^\\]+\\') -replace '\\','_') + "_$mode"  

    try{
        # search group by constructed name
        $grp = Get-ADGroup -Filter {SamAccountName -eq $grp_name}
        # if group not found, create it
        if (!$grp){
            $grp = New-ADGroup -Name $grp_Name -GroupScope DomainLocal -GroupCategory Security -PassThru
        }
        # ace variable
        $ace = $null
        # different aces for modify and list modes
        switch($mode){
            'modify' {  
                # create 'modify' ace for deepest level 
                $ace = New-Object System.Security.AccessControl.FileSystemAccessRule $grp.SamAccountName,"Modify","ContainerInherit,ObjectInherit","none","Allow"  
                # set next group mode
                $mode = 'list'  
            }
            'list' {  
                # create read ace for list group (this folder only)
                $ace = New-Object System.Security.AccessControl.FileSystemAccessRule $grp.SamAccountName,"Read","none","none","Allow"  
                # add last level group to current folder list group
                Add-ADGroupMember $grp -Members $last
            }
        }

        # set filesystem permission
        $acl = Get-ACL $current.FullName
        $acl.SetAccessRuleProtection($false,$true)
        $acl.SetAccessRule($ace)
        Set-ACL $current.FullName $acl

        write-Host "OK" -F Green  

        # set last group
        $last = $grp
        # set next level to parent folder
        $current = $current.Parent
    }catch{
        write-host $_.Exception.Message -F Red
        exit 1
    }
}
Grüße Uwe
nEmEsIs
nEmEsIs 06.08.2021 um 15:50:41 Uhr
Goto Top
Hallo Uwe

Ja cool vielen Dank.
Ich habe auch begonnen das zu Skripten aber bin nicht so weit gekommen, da ich an dem Loop für das List recht hängen geblieben bin. Ich poste nachher mal meinen Code.
Deinen werde ich nachher auch mal testen.

Zu der Frage / Antwort von @Festus94 und Uwe:
Die Berechnung werden von den "Profiltools" wie 8man und tenfold so nach unten hin aufgebaut und sind angeblich "MS Best Pr..."

Gute Reise @uwe

Mit freundlichen Grüßen Nemesis
nEmEsIs
nEmEsIs 06.08.2021 aktualisiert um 16:12:11 Uhr
Goto Top
Hi

was ich bis jetzt gebaut habe:

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Stand 03.08.2021
#Version 0.0.5

Param(
        [Parameter(Mandatory=$true)][String[]]$fullpath,
        [Parameter(Mandatory=$true)][switch[]]$permission_modify = $true, #$true/$false
        [Parameter(Mandatory=$false)][switch[]]$permission_read = $false, #$true/$false
        [Parameter(Mandatory=$false)][String[]]$ou ='OU=DEMO,OU=Groups,OU=Firma GmbH,DC=ads,DC=Firma,DC=de',  
        [Parameter(Mandatory=$false)][String[]]$dc = '$env:LOGONSERVER',  
        [Parameter(Mandatory=$false)][String[]]$prefix = 'FS',  
        [Parameter(Mandatory=$false)][switch[]]$ServerName = $false, #$true/$false
        [Parameter(Mandatory=$false)][switch[]]$ShareName = $true, #$true/$false
        [Parameter(Mandatory=$false)][String[]]$suffix_read = 're',  
        [Parameter(Mandatory=$false)][String[]]$suffix_modify = 'md',  
        [Parameter(Mandatory=$false)][String[]]$suffix_list = 'ls',  
        [Parameter(Mandatory=$false)][String[]]$delimiter = '_',  
        [Parameter(Mandatory=$false)][String[]]$GroupScope = 'Global' #DomainLocal,Global, Universal  
        )

Import-Module ActiveDirectory


$fullpath = $fullpath.ToLower()

if($fullpath) 
{
if ( ($fullpath.EndsWith("\")) )  
    {
        $fullpath = $fullpath.Substring(0,($($fullpath).Length-1))
    }
} 


if (!(Test-Path -Path $fullpath))
{
write-host "$fullpath existiert nicht, erstelle Ordner"  
New-Item -Path $fullpath -ItemType Directory -Force -InformationAction SilentlyContinue
}

$smbpath = [string]::Join('\', $fullpath.Split('\')[$($fullpath.Split('\').Length1..3)])  
$ServerNamePath = [string]::join("\",$fullpath.Split("\")[2])  
$ShareNamePath = [string]::join("\",$fullpath.Split("\")[3])  

Write-Host $smbpath
$undersmbpath = $smbpath -replace '\\',$delimiter  

Write-Host $undersmbpath

$folderpath = $fullpath.Replace($smbpath,"")  

Write-Host $folderpath 

$Groupnamepath = $folderpath -replace '\\',$delimiter  

Write-Host $Groupnamepath

if ($ServerName -eq $true)
{
    $Prefix = "$Prefix$delimiter$ServerNamePath"  
}

Write-Host $prefix


if ($ShareName -eq $true)
{
    $Prefix = "$Prefix$delimiter$ShareNamePath"  
}


Write-Host $prefix

$prefixgroupnamepath = "$prefix$delimiter$Groupnamepath$delimiter"  

Write-Host $prefixgroupnamepath

Write-Output $ou

if ($permission_modify -eq $true)
{
    $Groupmodify = "$prefixgroupnamepath$suffix_modify"  

        if (!(Get-ADGroup -filter {Name -eq $Groupmodify} -ErrorAction SilentlyContinue))
        { 
            New-ADGroup $Groupmodify -Path '$ou' -GroupCategory Security -GroupScope $GroupScope -description $fullpath  
        }
        else 
        {
            Write-Host "Gruppe $Groupmodify existiert bereits"  
        }

        $Permission = [system.Security.AccessControl.FileSystemRights]"DeleteSubdirectoriesAndFiles, Write, ReadAndExecute, ChangePermissions, TakeOwnership, Synchronize"  
        $ACL = Get-Acl $fullpath
        $ACLmodify = New-Object system.security.accesscontrol.filesystemaccessrule($Groupmodify, $Permission, 'ContainerInherit,ObjectInherit', "None", "Allow")  
        $ACL.SetAccessRule($ACLmodify) 
        Set-Acl -Path $fullpath -AclObject $ACL
}

Write-Host $Groupmodify

if ($permission_read -eq $true)
{
    $Groupread = "$prefixgroupnamepath$suffix_read"  

        if (!(Get-ADGroup -filter {Name -eq $Groupread} -ErrorAction SilentlyContinue))
        { 
            New-ADGroup $Groupread -Path '$ou' -GroupCategory Security -GroupScope $GroupScope -description $fullpath  
        }
        else 
        {
            Write-Host "Gruppe $Groupread existiert bereits"  
        }

        $Permission = [system.Security.AccessControl.FileSystemRights]"ReadAndExecute, Synchronize"  
        $ACL = Get-Acl $fullpath
        $ACLread = New-Object system.security.accesscontrol.filesystemaccessrule($Groupmodify, $Permission, 'ContainerInherit,ObjectInherit', "None", "Allow")  
        $ACL.SetAccessRule($ACLread) 
        Set-Acl -Path $fullpath -AclObject $ACL

}

Write-Host $Groupread

Und hier müsste dann der Loop für das List Recht kommen.

Mit freundlichen Grüßen Nemesis
nEmEsIs
Lösung nEmEsIs 17.08.2021 aktualisiert um 13:53:34 Uhr
Goto Top
Hi

habe das Skript fertiggestellt.


Permission.SetACLs&ADGroups.psm1

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
function Set-Permission
{
[CmdletBinding()]
Param(
        [Parameter(Mandatory=$true)][String]$FullPath,
        [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][ValidateSet($false,$true)][String]$permission_modify, #$true/$false
        [Parameter(Mandatory=$false)][ValidateNotNullOrEmpty()][ValidateSet($false,$true)][String]$permission_read = $false, #$true/$false
        [Parameter(Mandatory=$false)][String]$ou ='OU=DEMO,OU=Groups,OU=FIRMA GmbH,DC=ads,DC=FIRMA,DC=de',  
        [Parameter(Mandatory=$false)][String]$prefix = 'FS',  
        [Parameter(Mandatory=$false)][ValidateNotNullOrEmpty()][ValidateSet($false,$true)][String]$ServerName = $false, #$true/$false
        [Parameter(Mandatory=$false)][ValidateNotNullOrEmpty()][ValidateSet($false,$true)][String]$ShareName = $true, #$true/$false
        [Parameter(Mandatory=$false)][ValidateNotNullOrEmpty()][ValidateSet($false,$true)][String]$grouplowercase = $false, #$true/$false
        [Parameter(Mandatory=$false)][String]$suffix_read = 're',  
        [Parameter(Mandatory=$false)][String]$suffix_modify = 'md',  
        [Parameter(Mandatory=$false)][String]$suffix_list = 'ls',  
        [Parameter(Mandatory=$false)][String]$delimiter = '_',  
        [Parameter(Mandatory=$false)][ValidateNotNullOrEmpty()][ValidateSet("Global","Universal","DomainLocal")][String]$GroupScope = 'Global',  
        [Parameter(Mandatory=$false)][Int]$NTFSlongPath = '256'  
        )


#Globale Variablen für Backslash

$delimiter_path = "\"  
$illegal_Chars = '[&{}~#%]'  


# Active Directory Modul importieren

Import-Module ActiveDirectory

#Pfad auf illegale Zeichen prüfen
$invalid = [regex]::Matches($Fullpath, $illegal_Chars, 'IgnoreCase').Value | Sort-Object -Unique   

$Invalidfound = $invalid -ne $null
if ($InvalidFound)
{
  Write-Host "Im Pfad gefundene illegale Zeichen: $invalid" -ForegroundColor Red  
  Exit
}


#Pfad auf Länge prüfen
if ($FullPath.Name.Length -gt $NTFSlongPath)
    {
        Write-Host "$FullPath ist gößer oder gleich als $NTFSlongPath Zeichen" -ForegroundColor Red  
        Exit
    }

#Pfad auf Kleinschreibung anpassen
if($grouplowercase -eq "$true")  
    {
        $FullPath = $FullPath.ToLower()
    
        Write-Host "Kleinschreibung des Pfades aktiviert"  
    }

#FullPfad auf letztes Zeichen prüfen und bei einem \ entfernen

if($FullPath) 
    {
        if ( ($FullPath.EndsWith("\")) )  
            {
                $FullPath = $FullPath.Substring(0,($($FullPath).Length-1))
            }
    } 

#Pfad testen und wenn nicht existiert erstellen

if (!(Test-Path -Path $FullPath))
    {
        Write-Host "#############################################################"  
        Write-Host ""  
        Write-Host "Ordner oder Pfad wurden erstellt" -ForegroundColor Green  
        Write-Host ""  
        Write-Host "#############################################################"  
        New-Item -Path $FullPath -ItemType Directory -Force -InformationAction SilentlyContinue -ErrorAction SilentlyContinue
    }

#Variablen umwandeln für die Gruppenerzeugung

$SMBPath = [string]::Join('\', $FullPath.Split('\')[$($FullPath.Split('\').Length1..3)])  
$SMBPath = $SMBPath + $delimiter_path
$ServerNamePath = [string]::join("\",$FullPath.Split("\")[2])  
$ShareNamePath = [string]::join("\",$FullPath.Split("\")[3])  

$SMBPathwithdelimiter = $SMBPath -replace '\\',$delimiter  

#Erzeugung des reinen Ordnerpfades
$FolderPath = $FullPath.Replace($SMBPath,"")  


$GroupNamePath = $FolderPath -replace '\\',$delimiter  

#Gruppenbenamung anhand von Switch Parametern

#Servername in Gruppennamen

if ($ServerName -eq $true)
{
    $Prefix = "$Prefix$delimiter$ServerNamePath"  
}


#Freigabennamen in Gruppennamen

if ($ShareName -eq $true)
{
    $Prefix = "$Prefix$delimiter$ShareNamePath"  
}



$PrefixGroupNamePath = "$prefix$delimiter$GroupNamePath$delimiter"  


#Gruppe für Modify erzeugen

if ($permission_modify -eq $true)
{
    $ModifyGroupName = "$PrefixGroupNamePath$suffix_modify"  

        if (!(Get-ADGroup -filter {Name -eq $ModifyGroupName} -ErrorAction SilentlyContinue))
        { 
            Write-Host "#############################################################"  
            Write-Host ""  
            Write-Host "Gruppe $ModifyGroupName erstellt" -ForegroundColor Green  
            Write-Host ""  
            Write-Host "#############################################################"  
            New-ADGroup $ModifyGroupName -Path "$ou" -GroupCategory Security -GroupScope $GroupScope -description $FullPath -PassThru  

        }
        else 
        {
            Write-Host "#############################################################"  
            Write-Host ""  
            Write-Host "Gruppe $ModifyGroupName existiert bereits" -ForegroundColor Green  
            Write-Host ""  
            Write-Host "#############################################################"  
        }

        $Permission = [system.Security.AccessControl.FileSystemRights]"DeleteSubdirectoriesAndFiles, Write, ReadAndExecute, Synchronize"  
        $ACL = Get-Acl $FullPath
        if (!($ACL.Access.IdentityReference.Value -eq $ModifyGroupName))  
            {
                $ACLmodify = New-Object system.security.accesscontrol.filesystemaccessrule($ModifyGroupName, $Permission, 'ContainerInherit,ObjectInherit', "None", "Allow")  
                $ACL.SetAccessRule($ACLmodify) 
                Set-Acl -Path $FullPath -AclObject $ACL
                Write-Host "#############################################################"  
                Write-Host ""  
                Write-Host "Änderungsberechtigung auf $FullPath gesetzt" -ForegroundColor Green  
                Write-Host ""  
                Write-Host "#############################################################"  
            }
}



#Gruppe für Read erzeugen

if ($permission_read -eq $true)
{
    $ReadGroupName = "$PrefixGroupNamePath$suffix_read"  

        if (!(Get-ADGroup -filter {Name -eq $ReadGroupName} -ErrorAction SilentlyContinue))
        { 
            Write-Host "#############################################################"  
            Write-Host ""  
            Write-Host "Gruppe $ReadGroupName erstellt" -ForegroundColor Green  
            Write-Host ""  
            Write-Host "#############################################################"  
            New-ADGroup $ReadGroupName -Path "$ou" -GroupCategory Security -GroupScope $GroupScope -description $FullPath -PassThru  

        }
        else 
        {
            Write-Host "#############################################################"  
            Write-Host ""  
            Write-Host "Gruppe $ReadGroupName existiert bereits" -ForegroundColor Green  
            Write-Host ""  
            Write-Host "#############################################################"  
        }

        $Permission = [system.Security.AccessControl.FileSystemRights]"ReadAndExecute, Synchronize"  
        $ACL = Get-Acl $FullPath
        if (!($ACL.Access.IdentityReference.Value -eq $ReadGroupName))  
            {
                $ACLread = New-Object system.security.accesscontrol.filesystemaccessrule($ReadGroupName, $Permission, 'ContainerInherit,ObjectInherit', "None", "Allow")  
                $ACL.SetAccessRule($ACLread) 
                Set-Acl -Path $FullPath -AclObject $ACL
                Write-Host "#############################################################"  
                Write-Host ""  
                Write-Host "Leseberechtigung auf $FullPath gesetzt" -ForegroundColor Green  
                Write-Host ""  
                Write-Host "#############################################################"  
            }
}



#Gruppen für List erzeugen

#Ordner in Array schreiben bei Trennung \

$folderarray = $FolderPath.Split("\")  

#Anzahl Arrayelemente eins abziehen, da für den letzten Ordner kein List Recht benötigt werden, da dieser bereits die Read oder Modify Rechte besitzt 

$folderarray_count = $folderarray.Count - 1

#Zusammensetzten des vorderen Teils des Gruppennamnes

$GroupList_Base = "$prefix$delimiter"  

#SMBPfad auf letztes Zeichen prüfen und bei einem \ entfernen

if($SMBPath) 
{
if ( ($SMBPath.EndsWith("\")) )  
    {
       $ListPath_Base =   $SMBPath.Substring(0,($($SMBPath).Length-1))
    }
} 



#Variable mit leerem Array bilden

$ListGroupArray = @()

#Solange Schleife durchführen, bis eins weniger als die Ordneranzahl erreicht ist
for($i=0; $i -lt $folderarray_count; $i++)
{
    #Zusammenbauen des Gruppennamens mit Ordnernamen und delimiter

    $GroupList_Base= $GroupList_Base + $folderarray[$i] + $delimiter

    #Zusammenbauen des Gruppennamens mit Suffix für Listgruppen

    $ListGroupName = $GroupList_Base + $suffix_list

    $ListGroupArray += $ListGroupName

    #Pfad für das setzten der Listrechte zusammenbauen
    $ListPath_Base= $ListPath_Base + $delimiter_path + $folderarray[$i]



        # List Gruppe erstellen

       if (!(Get-ADGroup -filter {Name -eq $ListGroupName} -ErrorAction SilentlyContinue))
        { 
            Write-Host "#############################################################"  
            Write-Host ""  
            Write-Host "Gruppe $ListGroupName erstellt" -ForegroundColor Green  
            Write-Host ""  
            Write-Host "#############################################################"  
            New-ADGroup $ListGroupName -Path "$ou" -GroupCategory Security -GroupScope $GroupScope -description $ListPath_Base -PassThru  
        }
        else 
        {
            Write-Host "#############################################################"  
            Write-Host ""  
            Write-Host "Gruppe $ListGroupName existiert bereits" -ForegroundColor Blue  
            Write-Host ""  
            Write-Host "#############################################################"      
        }

        #List Gruppen berechtigen

        $Permission = [system.Security.AccessControl.FileSystemRights]"ReadAndExecute,Synchronize"  
        $ACL = Get-Acl $ListPath_Base
             if (!($ACL.Access.IdentityReference.Value -eq $ListGroupName))  
            {
                    $ACLlist = New-Object system.security.accesscontrol.filesystemaccessrule($ListGroupName, $Permission, "None", "None", "Allow")  
                    $ACL.SetAccessRule($ACLlist) 
                    Set-Acl -Path $ListPath_Base -AclObject $ACL
                    Write-Host "#############################################################"  
                    Write-Host ""  
                    Write-Host "Listberechtigung auf $ListPath_Base gesetzt" -ForegroundColor Green  
                    Write-Host ""  
                    Write-Host "#############################################################"  
             }




}

# Modify und/oder Read Gruppen der nächst höhren liegenden Listgruppe hinzufügen

$ListGroupArray_Count = $ListGroupArray.Count

if($ListGroupArray_Count -gt 0)
{

    if($permission_modify -eq $true)
    {
        Add-ADPrincipalGroupMembership -Identity $ModifyGroupName -Memberof $ListGroupArray[$ListGroupArray_Count-1]
        Write-Host "#############################################################"  
        Write-Host ""  
        Write-Host $ModifyGroupName -ForegroundColor Green
        Write-Host "in" -ForegroundColor Green  
        Write-Host $ListGroupArray[$ListGroupArray_Count-1] -ForegroundColor Green
        Write-Host "hinzugefügt" -ForegroundColor Green  
        Write-Host ""  
        Write-Host "#############################################################"  
    }

    if($permission_read -eq $true)
    {
        Add-ADPrincipalGroupMembership -Identity $ReadGroupName -Memberof $ListGroupArray[$ListGroupArray_Count-1]
        Write-Host "#############################################################"  
        Write-Host ""  
        Write-Host $ReadGroupName -ForegroundColor Green
        Write-Host "in" -ForegroundColor Green  
        Write-Host $ListGroupArray[$ListGroupArray_Count-1] -ForegroundColor Green
        Write-Host "hinzugefügt" -ForegroundColor Green  
        Write-Host ""  
        Write-Host "#############################################################"  
    }
}

#List Gruppe mit der darüberliegenden List Gruppe verschachteln

for($i = $ListGroupArray_Count - 1; $i-gt 0; $i--)
{
    Add-ADPrincipalGroupMembership -Identity $ListGroupArray[$i] -Memberof $ListGroupArray[$i-1]
    Write-Host "#############################################################"  
    Write-Host ""  
    Write-host $ListGroupArray[$i] -ForegroundColor Green
    Write-Host "in" -ForegroundColor Green  
    Write-Host $ListGroupArray[$i-1] -ForegroundColor Green
    Write-Host "hinzugefügt" -ForegroundColor Green  
    Write-Host ""  
    Write-Host "#############################################################"  
}
Write-Host "#############################################################"  
Write-Host ""  
Write-Host "Berechtigungen erfolgreich gesetzt" -ForegroundColor Green  
Write-Host ""  
Write-Host "#############################################################"  
}

Zusätzlich falls die berechtigten Ordner verschoben werden sollten ein Prüfung, ob die Zuordnung von ADGruppenbeschreibung zu realen Pfad noch stimmt

Permission.ADGroupFilePathScanner.psm1

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
function Get-PermissionsPathScanner
{
[CmdletBinding()]
Param( 
        [Parameter(Mandatory=$true)][String]$FullPath,
        [Parameter(Mandatory=$false)][String]$NetBiosDomain = "NETBIOSDOMAIN",  
        [Parameter(Mandatory=$false)][String]$Reportpath = "$Fullpath",  
        [Parameter(Mandatory=$false)][Int]$Depth
    )


$NetBiosDomain = $NetBiosDomain + "\\"  

$result = @()


if (!($Depth))
{
$ChildPathes = Get-ChildItem -Path $FullPath -Directory -Recurse
}
else 
{
$ChildPathes = Get-ChildItem -Path $FullPath -Directory -Depth $Depth 
}

foreach ($ChildPath in $Childpathes)
{
$ACL = Get-Acl $ChildPath.FullName
$ACEs = $ACL.GetAccessRules($true, $false ,[System.Security.Principal.NTAccount])

foreach ($ACE in $ACEs)
{
 $ADGroup = $ACE.IdentityReference 
 $ADGroup = $ADGroup.Value -replace $NetBiosDomain,''  
 $GroupDescription = Get-ADGroup $ADGroup -Properties Name, description | select description

 if (!($ChildPath.FullName -eq $GroupDescription.description))
 {

    $tempobject = New-Object PSCustomObject

    $tempobject | Add-Member -type NoteProperty -Name Pfad -Value $ChildPath.FullName
    $tempobject | Add-Member -type NoteProperty -Name ADGruppe -Value $ADGroup
    $tempobject | Add-Member -type NoteProperty -Name Gruppenbeschreibung -Value $GroupDescription.description

            $result += $tempobject
    }
}
$Header = @"  
"@  
$result | ConvertTo-Html -as List -Title "Gruppe passt nicht zu Pfad" -Property Pfad,ADGruppe,Gruppenbeschreibung | Out-File -FilePath "$Reportpath\Report.html"  
}
}

Mfg Nemesis