How to export user photos in O365 / Exchange Inline using Exchange Online Powershell

Below small script can be use to export photos from O365 / Exchange Online using powershell.

First you need to connect to exchange online.

#############################################

get-mailbox -ResultSize Unlimited | % {Get-UserPhoto $_.identity} | % {Set-Content -path “C:\Photos\$($_.identity).jpg” -value $_.picturedata -Encoding byte}

####################################################

How to export thumbnail/photos from Active Directory using powershell

Below is smal powershell script to export photos from the Active Directory using AD powershell.

#########################################################

$list=GET-ADuser –filter * -properties thumbnailphoto

Foreach ($User in $list)

{

$Directory=’C:\Photos\’

If ($User.thumbnailphoto)

  {

  $Filename=$Directory+$User.samaccountname+’.jpg’

  [System.Io.File]::WriteAllBytes($Filename, $User.Thumbnailphoto)

  }

}

#########################################################