폴더에 대한 그룹 권한 설정

폴더에 대한 그룹 권한 설정

하위 폴더가 많은 폴더가 있습니다.

  • D:\데이터\하위 폴더1
  • D:\데이터\하위 폴더2
  • D:\데이터\하위 폴더3
  • D:\데이터\하위 폴더4
  • D:\데이터\하위 폴더5
  • ...

이와 같이 각 하위 폴더에 대해 3개의 Active Directory 그룹을 생성해야 합니다.

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

이 작업이 완료되면 폴더, Activedirectory 그룹 및 권한을 매핑해야 합니다.

권한을 설정하는 것은 어려운 부분입니다. 이것이 내가 얼마나 멀리 왔는지입니다. 그룹을 권한에 바인딩한 다음 폴더에 적용하는 방법을 모르겠습니다.

$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


}

답변1

확인해보세요Don Jones의 이 예도움이 됩니다. 기본적으로 폴더에서 기존 acl 개체를 가져와 여기에 새 규칙(SetAccessRule)을 추가하면 규칙에는 주체(사용자 또는 그룹, 권한 및 허용 또는 거부 여부)가 포함됩니다. 업데이트된 acl객체는 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
  }

답변2

-PassThrucmdlet 에 매개 변수를 지정하면 New-ADGroup새 그룹이 반환됩니다. 반환된 ADGroup 개체에는 IdentityReference액세스 규칙에 대한 전달에 사용할 수 있는 SID 속성이 포함되어 있습니다.

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

관련 정보