Skip to content

Instantly share code, notes, and snippets.

@jeffpatton1971
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffpatton1971/ba425f457e4ee2794199 to your computer and use it in GitHub Desktop.
Save jeffpatton1971/ba425f457e4ee2794199 to your computer and use it in GitHub Desktop.
Set the thumbnailPhoto property for a user
function Set-UserPhoto
{
<#
.SYNOPSIS
Set the thumbnailPhoto property for a user
.DESCRIPTION
This function uses the ActiveDirectory Module to get and set
user properties. Specifically it replaces whatever is in the
thumbnailPhoto property with a photo.
.PARAMETER sAMAccountName
The username of the account you wish to update
.PARAMETER FileName
The path and filename of the image
#>
[CmdletBinding()]
Param
(
[string]$sAMAccountName,
[string]$FileName
)
Begin
{
try
{
Import-Module ActiveDirectory;
$User = Get-ADUser -Identity $sAMAccountName;
$Photo = [byte[]](Get-Content $FileName -Encoding byte);
}
catch
{
Write-Error $Error[0];
break;
}
}
Process
{
Set-ADUser $User -Replace @{thumbnailPhoto=$Photo};
}
End
{
Get-ADUser -Identity $User -Properties "thumbnailPhoto";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment