Last active
August 29, 2015 14:11
-
-
Save jeffpatton1971/ba425f457e4ee2794199 to your computer and use it in GitHub Desktop.
Set the thumbnailPhoto property for a user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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