Gruppenberechtigung für Ordner festlegen

Gruppenberechtigung für Ordner festlegen

Ich habe einen Ordner mit vielen Unterordnern

  • D:\Daten\Unterordner1
  • D:\Daten\Unterordner2
  • D:\Daten\Unterordner3
  • D:\Daten\Unterordner4
  • D:\Daten\Unterordner5
  • ...

Ich muss für jeden Unterordner wie diesen drei Active Directory-Gruppen erstellen.

  • FS_Data-Subfolder1_Read
  • FS_Data-Subfolder1_Change
  • FS_Data-Subfolder1_Full

und nachdem dies erledigt ist, muss ich Ordner, ActiveDirectory-Gruppe und Berechtigungen zuordnen.

Das Festlegen der Berechtigung ist der schwierige Teil. So weit bin ich gekommen. Ich weiß nicht, wie ich die Gruppe an die Berechtigung binde und sie dann auf den Ordner anwende.

$SharePath = "\\fs\data\"
$FSGroupPath = "OU=GROUPS,OU=Data,DC=DOMAIN,DC=LOCAL"

Get-ChildItem $SharePath | ForEach-Object {
$GroupNameRead = "FS_Data-" + $_ + "_Read"
$GroupNameChange = "FS_Data-" + $_ + "_Change"
$GroupNameFull = "FS_Data-" + $_ + "_Full"

New-ADGroup -Name $GroupNameRead -DisplayName $GroupNameRead -GroupScope DomainLocal -GroupCategory Security -Path $FSGroupPath -Description "Ger Läs Rättigheter till sökväg: FS\Data\$_"
New-ADGroup -Name $GroupNameChange -DisplayName $GroupNameChange -GroupScope DomainLocal -GroupCategory Security -Path $FSGroupPath -Description "Ger Ändra Rättigheter till sökväg: FS\Data\$_"
New-ADGroup -Name $GroupNameFull -DisplayName $GroupNameFull -GroupScope DomainLocal -GroupCategory Security -Path $FSGroupPath -Description "Ger Fulla Rättigheter till sökväg: FS\Data\$_"

$set_Group   = $GroupNameFull
$set_rights = Modify
$acl = Get-Acl $SharePath
$permission = $set_user,$set_rights,"Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
$acl | Set-Acl $SharePath


}

Antwort1

Sehen obdieses Beispiel von Don Joneshilft Ihnen: Sie nehmen im Grunde das vorhandene ACL-Objekt aus dem Ordner, fügen ihm eine neue Regel hinzu (SetAccessRule), und die Regel enthält den Auftraggeber (Benutzer oder Gruppe, das Recht und ob es ein Zulassen oder Verweigern ist). Das aktualisierte ACL-Objekt wird dann mit set-acl auf die Datei/den Ordner angewendet.

#ChangeACL.ps1
$Right="FullControl"

#The possible values for Rights are 
# ListDirectory, ReadData, WriteData 
# CreateFiles, CreateDirectories, AppendData 
# ReadExtendedAttributes, WriteExtendedAttributes, Traverse
# ExecuteFile, DeleteSubdirectoriesAndFiles, ReadAttributes 
# WriteAttributes, Write, Delete 
# ReadPermissions, Read, ReadAndExecute 
# Modify, ChangePermissions, TakeOwnership
# Synchronize, FullControl

$StartingDir=Read-Host "What directory do you want to start at?"
$Principal=Read-Host "What security principal do you want to grant" `
"$Right to? `n Use format domain\username or domain\group"

#define a new access rule.
#note that the $rule line has been artificially broken for print purposes.
#it needs to be one line. the online version of the script is properly
#formatted.
$rule=new-object System.Security.AccessControl.FileSystemAccessRule($Principal,$Right,"Allow")

foreach ($file in $(Get-ChildItem $StartingDir -recurse)) {
  $acl=get-acl $file.FullName

  #Add this access rule to the ACL
  $acl.SetAccessRule($rule)

  #Write the changes to the object
  set-acl $File.Fullname $acl
  }

Antwort2

Wenn Sie den -PassThruParameter im New-ADGroupCmdlet angeben, gibt es die neue Gruppe zurück. Das ADGroup-Objekt, das Sie zurückerhalten, enthält eine SID-Eigenschaft, die Sie verwenden können, IdentityReferenceum die Zugriffsregel zu übergeben:

$readGroup  = New-ADGroup -Name $GroupNameRead -DisplayName $GroupNameRead -GroupScope DomainLocal -GroupCategory Security -Path $FSGroupPath -Description "Ger Läs Rättigheter till sökväg: FS\Data\$_" -PassThru
if(-not($readGroup)) # Make sure it got created, if not, handle the error
{
    # Error handling in here
}
else
{
    $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($readGroup.SID,Read,Allow)
}

verwandte Informationen