我有一个包含大量安全组(包含学生和教师用户名的课程部分)的 Active Directory OU 我想通过 powershell 编写脚本,该脚本创建使用安全组名称命名的文件夹,然后为每个安全组分配修改权限到对应的文件夹。这是我的脚本
#get all security groups
$sec_groups = Get-ADObject -SearchBase "ou=class,ou=Groups,ou=Colleague,dc=school,dc=edu" -LDAPFilter "(name=13_su*)" -ResultSetSize 10 | FT Name -HideTableHeaders
ForEach ($sec_group in $sec_groups)
{
#create folder for each security group
$newPath = Join-Path -Path "\\server\classes" -childpath $sec_group
New-Item $newPath -type directory
#set permission for each folder
$acl = Get-Acl $newpath
$acl.SetAccessRuleProtection($True, $False)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("labadmins","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.AddAccessRule($rule)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$sec_group","Modify", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.AddAccessRule($rule)
Set-Acl $newPath $acl
}
为每个安全组创建文件夹成功,但设置$sec_group
权限失败。
我究竟做错了什么?