[SPS] Extract users’ LTHUMB profile picture
SharePoint normally uses the MThumb picture. This script gathers the LThumb picture for each profile from the “user profile picture” library.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
#start script If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } [system.reflection.assembly]::LoadWithPartialName("System.Web") $SUrl="http://pbnet-sps:9091" #MySiteURL #download function Download() { trap [Exception] { Write-Output "-------------------------------Error" Write-Output $_.Exception.Message Write-Output "-------------------------------Error" continue } $datel = Get-Date Write-Output "INFO: `t $datel `t Job Started" #Write-Host "Set Path to Store Pictures" $FilePath = "c:\temp\pix2\" write-host $SUrl $site=get-spsite $SUrl $context = Get-SPServiceContext $site $upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context) #Create WebRequest $WebRequest = new-object System.Net.WebClient $WebRequest.Credentials = [System.Net.CredentialCache]::DefaultCredentials #Display Pic URL foreach ($profile in $upm.GetEnumerator()) { #$profile=$upm.GetUserProfile($profile.UserAccount) $Picture=$profile["PictureURL"].Value $AccountName = $profile["AccountName"].value # Write-Host "$Picture ----- $AccountName" if(!([string]::IsNullOrEmpty($Picture))) { $FileName = $FilePath +$AccountName.SubString($AccountName.LastIndexOf("\")+1) + $Picture.SubString($Picture.LastIndexOf(".")) #$WebRequest.DownloadFile($picture,$FileName) #Write-Host $picture $test=$picture -replace "MThumb","LThumb" $WebRequest.DownloadFile($test,$FileName) Write-host $test # Write-Host "$Picture ----- $FileName" } } } Download |