.net - 如何使用 PowerShell 查找 Active Directory 类的 "Schema-Id-Guid"和属性的 "System-Id-Guid"

标签 .net powershell ldap

我需要创建一些新的访问控制条目 (ACE),以便使用 PowerShell 委派给特定的 Active Directory OU。

这些规则需要授予/拒绝访问“计算机”对象上的“NT AUTHORITY\SELF”用户帐户的特定属性。

我正在使用 System.DirectoryServices.ActiveDirectoryAccessRule .NET 类创建 ACE。 The constructor that I require to create this object需要所需属性和类的 GUID。

我现在可以使用我编写的以下 PowerShell 代码很好地创建此规则:

# Get the security descriptor for the desired OU
$ouPath = "AD:\\OU=TestOU,DC=example,DC=com"
$acl = Get-Acl $ouPath

# Get the SID of the "NT AUTHORITY\SELF" user account
$account = [System.Security.Principal.NTAccount]::New("NT AUTHORITY", "SELF")
$accountSID = $account.Translate([System.Security.Principal.SecurityIdentifier])

# Property values for ActiveDirectoryAccessRule
$identity = [System.Security.Principal.IdentityReference]$accountSID
$adRights = [System.DirectoryServices.ActiveDirectoryRights]("ReadProperty, WriteProperty")
$type = [System.Security.AccessControl.AccessControlType]("Allow")
$objectType = [System.Guid]::New("bf9679d9-0de6-11d0-a285-00aa003049e2")
$inheritanceType = [System.DirectoryServices.ActiveDirectorySecurityInheritance]("Descendents")
$inheritedObjectType = [System.Guid]::New("bf967a86-0de6-11d0-a285-00aa003049e2")

# Create the new rule object
$ace = [System.DirectoryServices.ActiveDirectoryAccessRule]::New($identity, $adRights, $type, $objectType, $inheritanceType, $inheritedObjectType)

# Add the rule to the ACL
$acl.AddAccessRule($ace)

# Change the security descriptor
Set-Acl -AclObject $acl $ouPath

上面的代码示例允许对 Computer 类的 Network-Address 属性进行读写。引用的 GUID 如下:

Network-Address: System-Id-Guid bf9679d9-0de6-11d0-a285-00aa003049e2

Computer: Schema-Id-Guid bf967a86-0de6-11d0-a285-00aa003049e2

我遇到的唯一问题是我必须手动查找所需属性和类的 GUID。

所以我的问题是:

有谁知道仅使用 CN 或 Ldap-Display-Name 来查找这些 GUID 的方法?

最佳答案

答案链接由 Theo 提供.

Get Property guid

我将复制/粘贴 Mathias R. Jessen 的答案:

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

  • 在 schemaNamingContext 中查询 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]
    

    关于.net - 如何使用 PowerShell 查找 Active Directory 类的 "Schema-Id-Guid"和属性的 "System-Id-Guid",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53964424/

    相关文章:

    powershell - Windows 7 SP1 上的 Powershell v4 中缺少 CMDLETS

    java - 在 Java 中使用 GSSAPI 身份验证时,来自 Active Directory 的搜索结果中的 LDAP Continuation Reference 错误

    java - Alfresco Ldap 在spaces.user_homes.regex.key 中使用组织

    C# 将 DLL 限制为只有一个实例

    c# - 我如何(优雅地)将文本框转置到字符串特定部分的标签上?

    c# - 请告诉我一个为委托(delegate)(或)函数指针显示 `need` 的情况

    c# - 是否可以从 Windows 窗体中的 SplitContainer 中删除 panel2?

    powershell - 使用 Powershell 作业、运行空间或工作流时,线程是否在不同的内核上执行?

    powershell - 在powershell中是否有!$等效项?

    python - 即使使用分页搜索,OpenLDAP 也不会搜索超过 500 个条目