用于设置文件夹及其子文件夹权限的PowerShell脚本

时间:2014-11-14 13:27:26

标签: powershell

我创建了一个对CREATOR,域用户和管理员具有读/写权限的文件夹。它工作得很好但是当我尝试访问我的共享文件夹时,我发现我没有写入权限。我也不能创建一个文件夹..请帮助我。

$UserDir = "$HomeDir\$Sam"
$User = Get-QADUser -DisplayName "$Sam"
New-Item -Path $HomeDir -Name $Sam -ItemType Directory
Get-Acl "$UserDir"
$acl = Get-Acl $UserDir
$acl.SetAccessRuleProtection($True, $False)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Administrators","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.AddAccessRule($rule)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("SAHRDAYA\Domain Admins","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.AddAccessRule($rule)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($userPrinc,@("FullControl", "Modify", "ReadAndExecute", "ListDirectory", "Read", "Write"), "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.AddAccessRule($rule)
Set-Acl $UserDir $acl

0 个答案:

没有答案