[英]How to insert or update properties in Active Directory Users and Groups
[英]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.