0 people like it.
Like the snippet!
¿
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
|
#r "System.DirectoryServices"
open System
open System.IO
open System.DirectoryServices
let cookieName = "cookie.bin"
let resourceDomain = "mydomain.net"
let groupSearchFilter = "(&(objectClass=group)(objectCategory=group)(name=Test Group))"
let cookiePath = String.Format("{0}\{1}", __SOURCE_DIRECTORY__, cookieName)
let getCookie path =
match File.Exists(path) with
| true -> Some(File.ReadAllBytes(path))
| false -> None
let setCookie path cookie =
try
File.WriteAllBytes(path, cookie)
Some(cookie)
with
| ex -> None
let modifyProxy (user:DirectoryEntry) found notFound =
user.Properties.["proxyAddresses"]
|> Seq.cast<string>
|> Seq.tryFindIndex(fun x -> x.StartsWith("sip:", StringComparison.InvariantCultureIgnoreCase))
|> function
| Some(index) ->found user.Properties.["proxyAddresses"] index
| None -> notFound user.Properties.["proxyAddresses"]
user.CommitChanges()
let setUserEnabled (user : DirectoryEntry) =
// Add or Update the proxy address.
let sip = String.Format("sip:{0}", user.Properties.["mail"].[0].ToString())
user.Properties.["msRTCSIP-PrimaryUserAddress"].Value <- sip
modifyProxy user (fun pc i -> pc.[i] <- sip) (fun pc -> pc.Add sip |> ignore)
let setUserDisabled (user : DirectoryEntry) =
// Remove the SIP address.
user.Properties.["msRTCSIP-PrimaryUserAddress"].Clear()
modifyProxy user (fun pc i -> pc.RemoveAt i) ignore
let update() =
let convert (results:ResultPropertyValueCollection) = [for o in results -> new DirectoryEntry(String.Format("LDAP://{0}/{1}", resourceDomain, o))]
let cookie = getCookie cookiePath
use de = new DirectoryEntry(String.Format("LDAP://{0}", resourceDomain))
use searcher = new DirectorySearcher(de, groupSearchFilter)
let flags = DirectorySynchronizationOptions.ObjectSecurity ||| DirectorySynchronizationOptions.IncrementalValues
let sync = match cookie.IsNone with
| true -> new DirectorySynchronization(flags)
| false -> new DirectorySynchronization(flags, cookie.Value)
searcher.DirectorySynchronization <- sync
use res = searcher.FindAll()
res
|> Seq.cast<SearchResult>
|> Seq.iter(fun x ->
(if x.Properties.Contains("member;range=1-1") then convert x.Properties.["member;range=1-1"] else []) |> List.iter setUserEnabled
(if x.Properties.Contains("member;range=0-0") then convert x.Properties.["member;range=0-0"] else []) |> List.iter setUserDisabled)
setCookie cookiePath (sync.GetDirectorySynchronizationCookie()) |> ignore
|
namespace System
namespace System.IO
namespace System.DirectoryServices
val cookieName : string
Full name: Script.cookieName
val resourceDomain : string
Full name: Script.resourceDomain
val groupSearchFilter : string
Full name: Script.groupSearchFilter
val cookiePath : string
Full name: Script.cookiePath
Multiple items
type String =
new : value:char -> string + 7 overloads
member Chars : int -> char
member Clone : unit -> obj
member CompareTo : value:obj -> int + 1 overload
member Contains : value:string -> bool
member CopyTo : sourceIndex:int * destination:char[] * destinationIndex:int * count:int -> unit
member EndsWith : value:string -> bool + 2 overloads
member Equals : obj:obj -> bool + 2 overloads
member GetEnumerator : unit -> CharEnumerator
member GetHashCode : unit -> int
...
Full name: System.String
--------------------
String(value: nativeptr<char>) : unit
String(value: nativeptr<sbyte>) : unit
String(value: char []) : unit
String(c: char, count: int) : unit
String(value: nativeptr<char>, startIndex: int, length: int) : unit
String(value: nativeptr<sbyte>, startIndex: int, length: int) : unit
String(value: char [], startIndex: int, length: int) : unit
String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: Text.Encoding) : unit
String.Format(format: string, [<ParamArray>] args: obj []) : string
String.Format(format: string, arg0: obj) : string
String.Format(provider: IFormatProvider, format: string, [<ParamArray>] args: obj []) : string
String.Format(format: string, arg0: obj, arg1: obj) : string
String.Format(format: string, arg0: obj, arg1: obj, arg2: obj) : string
val getCookie : path:string -> byte [] option
Full name: Script.getCookie
val path : string
type File =
static member AppendAllLines : path:string * contents:IEnumerable<string> -> unit + 1 overload
static member AppendAllText : path:string * contents:string -> unit + 1 overload
static member AppendText : path:string -> StreamWriter
static member Copy : sourceFileName:string * destFileName:string -> unit + 1 overload
static member Create : path:string -> FileStream + 3 overloads
static member CreateText : path:string -> StreamWriter
static member Decrypt : path:string -> unit
static member Delete : path:string -> unit
static member Encrypt : path:string -> unit
static member Exists : path:string -> bool
...
Full name: System.IO.File
File.Exists(path: string) : bool
union case Option.Some: Value: 'T -> Option<'T>
File.ReadAllBytes(path: string) : byte []
union case Option.None: Option<'T>
val setCookie : path:string -> cookie:byte [] -> byte [] option
Full name: Script.setCookie
val cookie : byte []
File.WriteAllBytes(path: string, bytes: byte []) : unit
val ex : exn
val modifyProxy : user:DirectoryEntry -> found:(PropertyValueCollection -> int -> unit) -> notFound:(PropertyValueCollection -> unit) -> unit
Full name: Script.modifyProxy
val user : DirectoryEntry
Multiple items
type DirectoryEntry =
inherit Component
new : unit -> DirectoryEntry + 4 overloads
member AuthenticationType : AuthenticationTypes with get, set
member Children : DirectoryEntries
member Close : unit -> unit
member CommitChanges : unit -> unit
member CopyTo : newParent:DirectoryEntry -> DirectoryEntry + 1 overload
member DeleteTree : unit -> unit
member Guid : Guid
member Invoke : methodName:string * [<ParamArray>] args:obj[] -> obj
member InvokeGet : propertyName:string -> obj
...
Full name: System.DirectoryServices.DirectoryEntry
--------------------
DirectoryEntry() : unit
DirectoryEntry(path: string) : unit
DirectoryEntry(adsObject: obj) : unit
DirectoryEntry(path: string, username: string, password: string) : unit
DirectoryEntry(path: string, username: string, password: string, authenticationType: AuthenticationTypes) : unit
val found : (PropertyValueCollection -> int -> unit)
val notFound : (PropertyValueCollection -> unit)
property DirectoryEntry.Properties: PropertyCollection
module Seq
from Microsoft.FSharp.Collections
val cast : source:Collections.IEnumerable -> seq<'T>
Full name: Microsoft.FSharp.Collections.Seq.cast
Multiple items
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = String
Full name: Microsoft.FSharp.Core.string
val tryFindIndex : predicate:('T -> bool) -> source:seq<'T> -> int option
Full name: Microsoft.FSharp.Collections.Seq.tryFindIndex
val x : string
String.StartsWith(value: string) : bool
String.StartsWith(value: string, comparisonType: StringComparison) : bool
String.StartsWith(value: string, ignoreCase: bool, culture: Globalization.CultureInfo) : bool
type StringComparison =
| CurrentCulture = 0
| CurrentCultureIgnoreCase = 1
| InvariantCulture = 2
| InvariantCultureIgnoreCase = 3
| Ordinal = 4
| OrdinalIgnoreCase = 5
Full name: System.StringComparison
field StringComparison.InvariantCultureIgnoreCase = 3
val index : int
DirectoryEntry.CommitChanges() : unit
val setUserEnabled : user:DirectoryEntry -> unit
Full name: Script.setUserEnabled
val sip : string
val pc : PropertyValueCollection
val i : int
PropertyValueCollection.Add(value: obj) : int
val ignore : value:'T -> unit
Full name: Microsoft.FSharp.Core.Operators.ignore
val setUserDisabled : user:DirectoryEntry -> unit
Full name: Script.setUserDisabled
Collections.CollectionBase.RemoveAt(index: int) : unit
val update : unit -> unit
Full name: Script.update
val convert : (ResultPropertyValueCollection -> DirectoryEntry list)
val results : ResultPropertyValueCollection
type ResultPropertyValueCollection =
inherit ReadOnlyCollectionBase
member Contains : value:obj -> bool
member CopyTo : values:obj[] * index:int -> unit
member IndexOf : value:obj -> int
member Item : int -> obj
Full name: System.DirectoryServices.ResultPropertyValueCollection
val o : obj
val cookie : byte [] option
val de : DirectoryEntry
val searcher : DirectorySearcher
Multiple items
type DirectorySearcher =
inherit Component
new : unit -> DirectorySearcher + 7 overloads
member Asynchronous : bool with get, set
member AttributeScopeQuery : string with get, set
member CacheResults : bool with get, set
member ClientTimeout : TimeSpan with get, set
member DerefAlias : DereferenceAlias with get, set
member DirectorySynchronization : DirectorySynchronization with get, set
member ExtendedDN : ExtendedDN with get, set
member Filter : string with get, set
member FindAll : unit -> SearchResultCollection
...
Full name: System.DirectoryServices.DirectorySearcher
--------------------
DirectorySearcher() : unit
DirectorySearcher(searchRoot: DirectoryEntry) : unit
DirectorySearcher(filter: string) : unit
DirectorySearcher(searchRoot: DirectoryEntry, filter: string) : unit
DirectorySearcher(filter: string, propertiesToLoad: string []) : unit
DirectorySearcher(searchRoot: DirectoryEntry, filter: string, propertiesToLoad: string []) : unit
DirectorySearcher(filter: string, propertiesToLoad: string [], scope: SearchScope) : unit
DirectorySearcher(searchRoot: DirectoryEntry, filter: string, propertiesToLoad: string [], scope: SearchScope) : unit
val flags : DirectorySynchronizationOptions
type DirectorySynchronizationOptions =
| None = 0L
| ObjectSecurity = 1L
| ParentsFirst = 2048L
| PublicDataOnly = 8192L
| IncrementalValues = 2147483648L
Full name: System.DirectoryServices.DirectorySynchronizationOptions
field DirectorySynchronizationOptions.ObjectSecurity = 1L
field DirectorySynchronizationOptions.IncrementalValues = 2147483648L
val sync : DirectorySynchronization
property Option.IsNone: bool
Multiple items
type DirectorySynchronization =
new : unit -> DirectorySynchronization + 4 overloads
member Copy : unit -> DirectorySynchronization
member GetDirectorySynchronizationCookie : unit -> byte[]
member Option : DirectorySynchronizationOptions with get, set
member ResetDirectorySynchronizationCookie : unit -> unit + 1 overload
Full name: System.DirectoryServices.DirectorySynchronization
--------------------
DirectorySynchronization() : unit
DirectorySynchronization(option: DirectorySynchronizationOptions) : unit
DirectorySynchronization(sync: DirectorySynchronization) : unit
DirectorySynchronization(cookie: byte []) : unit
DirectorySynchronization(option: DirectorySynchronizationOptions, cookie: byte []) : unit
property Option.Value: byte []
property DirectorySearcher.DirectorySynchronization: DirectorySynchronization
val res : SearchResultCollection
DirectorySearcher.FindAll() : SearchResultCollection
type SearchResult =
member GetDirectoryEntry : unit -> DirectoryEntry
member Path : string
member Properties : ResultPropertyCollection
Full name: System.DirectoryServices.SearchResult
val iter : action:('T -> unit) -> source:seq<'T> -> unit
Full name: Microsoft.FSharp.Collections.Seq.iter
val x : SearchResult
property SearchResult.Properties: ResultPropertyCollection
ResultPropertyCollection.Contains(propertyName: string) : bool
Multiple items
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member Head : 'T
member IsEmpty : bool
member Item : index:int -> 'T with get
member Length : int
member Tail : 'T list
static member Cons : head:'T * tail:'T list -> 'T list
static member Empty : 'T list
Full name: Microsoft.FSharp.Collections.List<_>
val iter : action:('T -> unit) -> list:'T list -> unit
Full name: Microsoft.FSharp.Collections.List.iter
DirectorySynchronization.GetDirectorySynchronizationCookie() : byte []
More information