Bulk Upload Photos to Exchange Online

Ever since the advent of DirSync, you've been able to add a picture's binary content to the thumbnailPhoto attribute in AD and synchronize it to Office 365.  This blob would be rendered as a photo next to the user's name in Outlook, OWA, and Lync.  Pretty cool, right?

That's great in smaller environments, but what happens if you have tens or hundreds of thousands of users?  Administrators might be worried about the amount of bloat this adds to their AD DS database.  And if the DCs have small disk volumes holding ntds.dit, running out of space is a real concern.

Fortunately, you can upgrade photos directly to Exchange Online!

This script is really just a framework--there's lots you can do with it.  It depends on a few core things:

- All photos are stored in a single directory
- All photos are named something like alias.jpg or similar format.

 
# Office 365 Admin Credentials
$userAdmin = "o365admin@tenant.onmicrosoft.com"
$userAdminPass = "Password123"
$securePassword = ConvertTo-SecureString $userAdminPass  -AsPlainText  -Force
$global:adminCredential = New-Object  -TypeName System.Management.Automation.PSCredential  -argumentlist $userAdmin,$securePassword
$photoPath = “C:\temp\EXOPhotos”

Import-Module MSOnline

Write-Host  -ForegroundColor Green "Connecting to Office 365 ..."
$Office365Session = New-PSSession  -ConfigurationName Microsoft.Exchange  -ConnectionUri https://outlook.office365.com/powershell-liveid/?proxymethod=rps  -Credential $adminCredential  -Authentication Basic  -AllowRedirection
Import-PSSession $Office365Session  -AllowClobber  -WarningAction SilentlyContinue  -EA SilentlyContinue
Connect-MSOLService  -Credential $adminCredential 

$photos = gci  -Path $photoPath\*.jpg

Foreach ($file in $photos) {
       $user = $file.name.Replace(".jpg","")
       Set-UserPhoto -Identity $user -PictureData ([System.IO.File]::ReadAllBytes($file.FullName)) -Confirm:$false
       }

Of course, this is a simple sample--any way you can figure out how to associate your images with your users will work.