【问题标题】:Get Property guid获取物业指南
【发布时间】:2018-07-13 01:52:33
【问题描述】:

这是上下文:我正在尝试为“Authenticated Users”组设置一堆属性。为此,我编写了以下脚本:

# 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。

【问题讨论】:

    标签: windows powershell active-directory


    【解决方案1】:

    您可以从架构中检索属性的 GUID:

    1. 在 schemaNamingContext 中查询 attributeSchema 对象
    2. 过滤ldapDisplayName,GUI 显示的属性名称
    3. 获取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

    【讨论】:

    • 非常感谢!我尝试过类似的方法,但现在我意识到我正在使用对象的 ObjectGUID 属性,这就是为什么它之前不起作用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-09
    • 1970-01-01
    • 1970-01-01
    • 2013-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多