C# 查询具有其他属性的Active Directory组
我可以使用以下内容查询我的Active Directory组:C# 查询具有其他属性的Active Directory组,c#,.net,f#,active-directory,ldap,C#,.net,F#,Active Directory,Ldap,我可以使用以下内容查询我的Active Directory组: open System.DirectoryServices.AccountManagement let specialGroups () = let ctx = new PrincipalContext( contextType = ContextType.Domain, name = "domain.net", conta
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这样
Get-ADGroup "GROUPNAME.UG" -Properties Mail
您可以通过检索基础
DirectoryEntry
对象,然后访问其properties
集合来获取属性。下面是一个为主体
对象定义getProperty
函数的示例,然后使用它对邮件
属性进行过滤:
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 |]
open System.DirectoryServices
open System.DirectoryServices.AccountManagement
让getProperty名称(组:主体)=
让entry=group.getUnderlineObject()|>unbox
[|用于entry.Properties中的值。[name]->value |>string |]
让特殊组()=
设ctx=新的PrincipalContext(
contextType=contextType.Domain,
name=“domain.net”,
container=“DC=domain,DC=net”)
设allGroups=newgroupprincipal(ctx,“*”)
设srch=新的PrincipalSearcher(所有组)
[|对于srch.FindAll()|>Seq.filter(getProperty“Mail”>>Array.isEmpty)中的组)->group |]
这不是C#,对吧?无论如何,这可能会有帮助