繁体   English   中英

查询具有其他属性的Active Directory组

[英]Query Active Directory Groups With Additional Properties

我可以使用以下查询我的Active Directory组:

open System.DirectoryServices.AccountManagement

let specialGroups () =
    let ctx = new PrincipalContext(
                contextType = ContextType.Domain, 
                name = "domain.net", 
                container = "DC=domain,DC=net")
    let allGroups = new GroupPrincipal(ctx, "*")
    let srch = new PrincipalSearcher(allGroups)
    [| for group in srch.FindAll() -> group |]

如何像PowerShell这样添加某些属性,例如Mail?

Get-ADGroup "GROUPNAME.UG" -Properties Mail

您可以通过检索基础DirectoryEntry对象,然后访问其Properties集合来获取Properties 这是一个为Principal对象定义getProperty函数,然后使用它过滤"Mail"属性的示例:

open System.DirectoryServices
open System.DirectoryServices.AccountManagement

    let getProperty name (group: Principal) =
    let entry = group.GetUnderlyingObject() |> unbox<DirectoryEntry>
    [| for value in entry.Properties.[name] -> value |> string |]

let specialGroups () =
    let ctx = new PrincipalContext(
                contextType = ContextType.Domain, 
                name = "domain.net", 
                container = "DC=domain,DC=net")
    let allGroups = new GroupPrincipal(ctx, "*")
    let srch = new PrincipalSearcher(allGroups)
    [| for group in srch.FindAll() |> Seq.filter (getProperty "Mail" >> Array.isEmpty) -> group |]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM