Last active
May 4, 2018 01:48
-
-
Save zailleh/891300b66ee7eb4f1fd09c97e02e9e7a to your computer and use it in GitHub Desktop.
Powwershell script that will extract Active Directory user Thumbnail Images to files. Output directory is the only parameter. Will use your local/default domain controller & domain.
This file contains hidden or 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
################################################################################ | |
# AD PROFILE PICTURE EXTRACTOR # | |
################################################################################ | |
# THIS SCRIPT WILL GET THE thumbnailPhoto ATTRIBUTE FROM ACTIVE DIRECTORY USER # | |
# AND SAVE TO JPEG # | |
# # | |
# AUTHOR: TIM CALDWELL # | |
# DATE: 21/02/2014 # | |
################################################################################ | |
param( | |
[Parameter( | |
Mandatory=$true, | |
HelpMessage="Output path of the resulting Jpeg Files", | |
Position=1 | |
)] | |
[string]$savePath #This parameter is required to run the script | |
) | |
$savePath = $savePath.TrimEnd('"\')+'\' #ensures the last char is a backslash | |
#Load our image converter | |
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | |
Import-Module "ActiveDirectory" | |
$imageConverter = New-Object System.Drawing.ImageConverter | |
#Retrieve all enabled users that have a thumbnail photo image | |
$allUsers = Get-ADUser -Filter {enabled -eq $true -and thumbnailPhoto -like '*'} -Properties thumbnailPhoto | Select samAccountName,thumbnailPhoto | |
#Convert each thumbnail photo from byte array to jpeg image and save | |
ForEach($user in $allUsers) { | |
$samAccountName = $user.samAccountName.Trim() | |
$thumbnailPhoto = $user.thumbnailPhoto | |
if ($thumbnailPhoto -ne $null) | |
{ | |
$outFile = $savePath + $samAccountName + '.jpg' | |
#$outFile | |
$Image = [System.Drawing.Image]$imageConverter.ConvertFrom([Byte[]]$thumbnailPhoto) | |
$Image.Save($outFile,[System.Drawing.Imaging.ImageFormat]::Jpeg) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment