Active Directory – User Bilder – Outlook 2010 / Lync 2010 – Teil 2

Jetzt werde ich zeigen, wie man das zuvor aktivierte Feature auch benutzen kann, bzw. Bilder in das Active Directory laden kann.

Einschränkungen für Bilder

  • Bilder müssen kleiner als 10 KB sein
  • Bilder müssen im JPG oder GIF Format vorlieren

Bilder in das Active Directory laden

Dem Benutzer manuel.maliszewski wird das Bild „C:\Users\chilli\Desktop\manuel.maliszewski.jpg“ zugeordnet und hoch geladen.

Import-RecipientDataProperty -Identity manuel.maliszewski -Picture -FileData ([Byte[]]$(Get-Content -path "C:\Users\chilli\Desktop\manuel.maliszewski.jpg" -Encoding Byte -ReadCount 0))

Bilder hochladen automatisieren

Damit das folgendes Script funktioniert, müssen die Bilder im Verzeichnis „C:\Photos“ vorname.nachme.jpg heißen. Der Aufruf würde dann so aussehen: script.ps -all

param([Switch]$all, [String]$UserName)

#Default Values. Change them based on your environment.
$DefaultPhotoPath = 'C:\Photos'

Function CheckPhoto(){
 Write-Warning "Validating file(s).."
 Write-Host "File exists... " -nonewline
 If (Test-Path $PhotoPath)
 {
 Write-Host "[OK]" -ForeGroundColor Green
 Write-host "Photo size... " -nonewline
 $PhotoSize = Get-ChildItem $PhotoPath | select Length
 If ($PhotoSize.Length -le 10000) { Write-Host "[OK]" -ForeGroundColor Green } Else { Write-Host "[Fail]" -ForeGroundColor Red; exit }
 }
 Else
 {
 Write-Host "[Fail]" -ForeGroundColor Red
 Exit
 }
}

Function UploadAll(){
 ForEach ($TempFile in Get-ChildItem $DefaultPhotoPath | Where-Object { $_.Extension -eq ".jpg" } )
 {
  $TempUserName = $TempFile.Name.substring(0, $TempFile.Name.Length - 4)
  Write-Host $TempUserName -ForeGroundColor Yellow -NoNewLine
  Import-RecipientDataProperty -Identity $TempUserName -Picture -FileData ([Byte[]]$(Get-Content -path $TempFile.Fullname -Encoding Byte -ReadCount 0))
  Write-Host "[Done]" -ForeGroundColor Green
 }
}

If ( $all -eq $true)
 {
 Write-Warning " ## This action will upload all pictures of C:\Photos to the AD users."
 Write-Warning " ## All pictures must have the same name of the usernames"
 Write-Warning "Are you sure that you want upload all pictures to the users (Y/N)?"
 $Opt = Read-Host
 If ( $Opt -eq 'y' ) { UploadAll; } Else { Write-Host "No changes were made."; Exit }
 }
Else
 {
 $PhotoPath = $DefaultPhotoPath + $UserName + '.jpg'
 CheckPhoto;
 If ( $AbortMission -eq '$true' ) { Write-Error "Please, review the errors and try again." } Else { Import-RecipientDataProperty -Identity $UserName -Picture -FileData ([Byte[]]$(Get-Content -path $PhotoPath -Encoding Byte -ReadCount 0)) }
 }

Dateinamen anpassen

Um den Upload Prozess zu automatisieren, ist es sinnvoll alle Bilder in dem Syntax vorname.nachname.jpg zu speichern. Da das in der Regel nicht der Fall ist, kann mit einigen Tools Dateinamen umbenennen. Wir haben z.B. Bilder im Format Nachname-Vorname_s.jpg und müssen diese entsprechend anpassen. Dafür kann man z.B. Total Commander benutzen und mit dem Dateiumbennenungs-Feature arbeiten.

In dem Beispiel würde das dann so aussehen:

Suchen nach: (.*)\-(.*)\_s.jpg
Ersetzen mit: $2.$1.jpg

Links

Kommentar verfassen

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.