Skip to content

Instantly share code, notes, and snippets.

@IAMPetro
Last active December 11, 2016 22:22
Show Gist options
  • Save IAMPetro/e77e287fc8b205bb4a52be1b1c171d4c to your computer and use it in GitHub Desktop.
Save IAMPetro/e77e287fc8b205bb4a52be1b1c171d4c to your computer and use it in GitHub Desktop.
Exchange: Example in uploading thumbnail into Active Directory
function Add-UserProfilePicture
{
<#
.Synopsis
This is a simple approach to uploading a binary file into an active directory users AD object.
.Example
C:\> Add-UserProfilePicture -user "Joe Bloggs" -picture "C:\images\Joe_Bloggs.jpg"
.Notes
Name: Add-UserProfilePicture
Author: Petro Margaritis
Last Edit: 19/05/2012
Keywords: Active Directory, Profile Photos, Exchange
.Link
http://www.iampetro.com/
#>
Param (
[parameter(Mandatory=$true)][string]$User,
[parameter(Mandatory=$true)][string]$PicturePath
)
# Report Variables
$success = "True"
$Error = $null
# Upload thumbnailPhoto
Import-RecipientDataProperty -Identity $userName -Picture -FileData ([Byte[]]$(Get-Content -Path $PicturePath -Encoding Byte -ReadCount 0))
write-host "The profile picture for" $userName "has been uploaded successfully" -foregroundcolor Green
# Export progress to .csv file
$outstring = $User, $PicturePath, $success
$outstring -join "," >> "C:\images\UserProfileUpload_Output.csv"
# Export Errors if any occurred
if ($Error -ne $null)
{
$Error >> "C:\images\UserProfileUpload_Errors.csv"
$Error.Clear()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment