jpegphoto using powershell

$username = "jjjjjj"
$jpgfile = ".\test.jpg"
$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$root = $dom.GetDirectoryEntry()
$search = [System.DirectoryServices.DirectorySearcher]$root
$search.Filter = "(&(objectclass=user)(objectcategory=person)(samAccountName=$username))"
$result = $search.FindOne()

if ($result -ne $null)
{
 $user = $result.GetDirectoryEntry()
 [byte[]]$jpg = Get-Content $jpgfile -encoding byte
 $user.put("jpegphoto",  $jpg )
 $user.setinfo()
 Write-Host $user.displayname " updated"
}
else {Write-Host $struser " Does not exist"}

To Erase change $user.put line to

$user.Properties["jpegPhoto"].Clear()
Comments