Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DmitriyVlasov/57279bab3d2924f06e25 to your computer and use it in GitHub Desktop.
Save DmitriyVlasov/57279bab3d2924f06e25 to your computer and use it in GitHub Desktop.
#r "System.DirectoryServices.AccountManagement.dll"
open System.DirectoryServices.AccountManagement
let testSearch fullName =
let ctx = new PrincipalContext(ContextType.Domain)
let u = new UserPrincipal(ctx)
u.Surname <- fullName
use ps = new PrincipalSearcher(u)
ps.FindAll()
|> Seq.cast<System.DirectoryServices.AccountManagement.UserPrincipal>
for r in testSearch "Ivanov" do
printfn "DistinguishedName: %s;" r.DistinguishedName
printfn "Guid: %A;"r.Guid
printfn "Name: %s:" r.Name
printfn "SamAccountName: %s;" r.SamAccountName
printfn "Sid: %A;" r.Sid
printfn "UserPrincipalName: %s;" r.UserPrincipalName
printfn ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment