Uploading pictures into ActiveDirectory remotely via PowerShell

32

One can upload pictures into PowerShell remotely. A few requirements:
1. Install RSAT; ; that’s adding the Feature in Computer Management
2. Have remote web services running on AD
3. Have sufficient access; you must be member of either the Organization Management or Recipient Management role groups to upload the pictures.
4. Have a set of photos, preferably named with the user accounts, JPGs, 96×96 and less than 10kb

Here’s what’s needed in PowerShell to get started using AD CmdLets:

Import-module ActiveDirectory
if ((Get-PSSnapin -Name ActiveDirectory -ErrorAction SilentlyContinue) -eq $null ){
			import-module ActiveDirectory
}

here’s how to see the existing picture for a given user:

$user = Get-ADUser [user] -Properties thumbnailphoto
$user.thumbnailphoto.length
$user.thumbnailphoto | Set-Content "C:tempJtest3a.jpg" -Encoding byte -Force

Testing in Outlook: Pictures are cached in Outlook for the duration of the session. To check whether the picture is available, one has to totally exit Outlook.

Let’s get all the files to process:

$LocalFiles = get-childitem -Path $WorkingPath -filter $TypeFilter | where {!$_.PSIsContainer} 

To upload the picture, get the user:

$User = Get-ADUser -Filter {SamAccountName -eq $Name}

Let’s get the photo after resizing to 96×96 ensuring it is less than 10k

$Photo = [byte[]](Get-Content "$WorkingPath$File" -Encoding byte)
Set-ADUser $Name -Replace @{thumbnailPhoto=$Photo}

Share this entry

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents

Categories

Categories