Powershell是一种在Windows操作系统上管理和自动化任务的强大脚本语言。通过Powershell,可以为所有用户启用组织单位(OU)的固有权限。下面是一个完善且全面的答案:
下面是使用Powershell为所有用户启用OU的固有权限的示例代码:
# 导入Active Directory模块
Import-Module ActiveDirectory
# 获取OU的DistinguishedName
$ouDN = "OU=Users,DC=example,DC=com"
# 获取OU的固有权限
$ouACL = Get-Acl "AD:\$ouDN"
# 启用对象权限
$ouACL.SetAccessRuleProtection($true, $false)
$ouACL.AddAccessRule((New-Object System.DirectoryServices.ActiveDirectoryAccessRule("Authenticated Users", "ReadProperty, WriteProperty", "Allow", "Descendents", "None")))
# 启用属性权限
$ouACL.AddAccessRule((New-Object System.DirectoryServices.ActiveDirectoryAccessRule("Authenticated Users", "ReadProperty", "Allow", "Descendents", "None")))
# 更新OU的权限
Set-Acl "AD:\$ouDN" $ouACL
请注意,上述示例代码中的"OU=Users,DC=example,DC=com"需要替换为实际的OU的DistinguishedName。此外,执行此脚本需要具有适当的权限,建议以管理员身份运行Powershell。
领取专属 10元无门槛券
手把手带您无忧上云