Establecer permiso de grupo en la carpeta

Establecer permiso de grupo en la carpeta

Tengo una carpeta con muchas subcarpetas.

  • D:\Datos\Subcarpeta1
  • D:\Datos\Subcarpeta2
  • D:\Datos\Subcarpeta3
  • D:\Datos\Subcarpeta4
  • D:\Datos\Subcarpeta5
  • ...

Necesito crear tres grupos de directorio activo para cada subcarpeta como este.

  • FS_Data-Subcarpeta1_Read
  • FS_Datos-Subcarpeta1_Cambiar
  • FS_Data-Subfolder1_Full

y una vez hecho esto, tengo que asignar la carpeta, el grupo de Activedirectory y el permiso.

Establecer el permiso es la parte difícil. hasta aquí llegué. No sé cómo vincular el grupo al permiso y luego aplicarlo a la carpeta.

$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


}

Respuesta1

Ve sieste ejemplo de Don Jonesle ayuda: básicamente toma el objeto acl existente de la carpeta, le agrega una nueva regla (SetAccessRule) y la regla contiene el principal (usuario o grupo, el derecho y si es permitir o denegar). El aclobject actualizado luego se aplica al archivo/carpeta usando set-acl.

#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
  }

Respuesta2

Cuando especifica el -PassThruparámetro en el New-ADGroupcmdlet, devuelve el nuevo grupo. El objeto ADGroup que recupera contiene una propiedad SID que puede usar para pasar IdentityReferencela regla de acceso:

$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)
}

información relacionada