SharePoint: Benutzerprofilbilder exportieren

Um die Benutzerprofilbilder aller SharePoint-User schnell vom SharePoint ins Dateisystem zu exportieren, eignet sich folgendes PowerShell-Script:

$username="<user>"
$password="<pwd>"
$domain="<domain>"

$wc = New-Object System.Net.WebClient
$wc.Credentials=new-object System.Net.NetworkCredential($username, $password, $domain)

$siteurl = "<mysiteurl>"
$serviceContext = Get-SPServiceContext -Site $siteUrl
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);
$profiles = $profileManager.GetEnumerator()

foreach ($profile in $profiles) {
  $user=$profile["UserName"].Value
  Write-Output('downloading picture for user ' + $user)
  $picUrl = $profile["PictureURL"].Value

  Try{
    if($picUrl) {
      $wc.DownloadFile($picUrl, "C:\TEMP\ProfilePictures\$user.jpg")
      Write-Output('saved picture for user ' + $user)
    }
    else {
      Write-Output('could not find picture for user ' + $user)
    }
  }
  Catch{
    $ErrorMessage = $_.Exception.Message
    Write-Error("Error downloading picture for user "+$user)
    Write-Error($ErrorMessage)
  } 
} 

Alle vorhandenen Profilbilder sollten nun unter dem gewählten Pfad gesichert worden sein.

2017-01-10T13:53:57+00:00