
たくさんのサブフォルダがあるフォルダがあります
- D:\データ\サブフォルダ1
- D:\データ\サブフォルダ2
- D:\データ\サブフォルダ3
- D:\データ\サブフォルダ4
- D:\データ\サブフォルダ5
- ...
このようにサブフォルダーごとに 3 つの Active Directory グループを作成する必要があります。
- FS_データ-サブフォルダ1_読み取り
- FS_データ-サブフォルダ1_変更
- FS_データ-サブフォルダ1_フル
これが完了したら、フォルダー、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
確認するドン・ジョーンズの例次のように役立ちます: 基本的に、フォルダーから既存の 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
-PassThru
コマンドレットでパラメータを指定すると、新しいグループが返されます。返される ADGroup オブジェクトには、アクセス ルールにNew-ADGroup
渡すために使用できる SID プロパティが含まれています。IdentityReference
$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)
}