这是上下文:我正在尝试为“经过身份验证的用户”组设置一堆属性。为此,我编写了以下脚本:
# GETTING AUTHENTICATED USERS SID
$sid1 = "S-1-5-11"
$objSID1 = New-Object System.Security.Principal.SecurityIdentifier($sid1)
# GETTING AUTHENTICATED ACL
$acl = Get-Acl -Path "AD:DC=*****,DC=*****"
# CREATING RULE ATTTIBUTES
$objectGuid = New-Object Guid 5f332e20-9eaa-48e7-b8c4-f4431fef859a
$identity = [System.Security.Principal.IdentityReference] $objSID1
$adRights = [System.DirectoryServices.ActiveDirectoryRights] "ReadProperty,WriteProperty"
$type = [System.Security.AccessControl.AccessControlType] "Allow"
$inheritanceType = [System.DirectoryServices.ActiveDirectorySecurityInheritance] "Descendents"
$inheritedobjectguid = New-Object Guid bf967aba-0de6-11d0-a285-00aa003049e2
# CREATING THE NEW RULE
$ace = New-Object System.DirectoryServices.ActiveDirectoryAccessRule $identity, $adRights, $type, $objectGuid, $inheritanceType, $inheritedobjectguid
# SETTING THE NEW RULE
$acl.AddAccessRule($ace)
Set-Acl -AclObject $acl "AD:DC=*****,DC=*****"
最终结果应该是这样:
一件重要的事情是,我试图设置的是属性,而不是权限。而且该属性并非在所有计算机上都具有相同的GUID,因为我在此脚本之前使用了另一个脚本来创建它。
问题如下:
在我设置$objectGuid
变量的代码中,我已经硬编码了所需的GUID。我需要知道的是,是否有任何方法可以使用PowerShell获取属性的GUID。
答案 0 :(得分:1)
您可以从架构中检索属性的GUID:
attributeSchema
对象ldapDisplayName
上过滤,GUI显示的属性名称schemaIDGUID
属性值并在ACE中使用它为简单起见,我将使用RSAT ActiveDirectory
模块,但是您可以对任何ldap客户端执行此操作:
$attrSchemaParams = @{
SearchBase = (Get-ADRootDSE).schemaNamingContext
Filter = "ldapDisplayName -eq 'pwmEventLog' -and objectClass -eq 'attributeSchema'"
Properties = 'schemaIDGUID'
}
$pwmEventLogSchema = Get-ADObject @attrSchemaParams
$pwmEventLogGUID = $pwmEventLogSchema.schemaIDGuid -as [guid]
现在使用$pwmEventLogGUID
代替$objectGuid