Created
February 26, 2015 04:17
-
-
Save bradmb/3961b39f7c4beec7a5fb to your computer and use it in GitHub Desktop.
Query Active Directory (using sAMAccountName) and Return A Thumbnail Photo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System.DirectoryServices | |
/// Gets a user's thumbnail photo from active directory. Returns null if no image found. | |
let ActiveDirectoryImageFor(samAccount:string):byte[] = | |
use adSearcher = new DirectorySearcher() | |
adSearcher.Filter <- "(&(objectClass=user) (sAMAccountName=" + samAccount + "))" | |
let adResult = adSearcher.FindOne() | |
if adResult = null | |
then | |
null | |
else | |
use adUser = new DirectoryEntry(adResult.Path) | |
let adJpeg = adUser.Properties.["thumbnailPhoto"] | |
let adImageData = if (adJpeg.Value :? byte[]) then adJpeg.Value :?> byte[] else null | |
adImageData |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment