Set PictureUrl as default unless another picture is present (PowerShell)

Introduction

This script shows how to Set PictureUrl as default unless another picture is present.

Scenarios

This script will set a default picture for the PictureUrl in a list where all user information are stored .If users don't specify a picture, the default picture will be used ..

Script

This script contains one advanced functions Set-OSCSPUserPhoto, you can use this script in the following ways:

Method 1:

  1. Download the script and open the script file with Notepad or any other script editors.
  2. Scroll down to the end of the script file, and then add     the example command which you want to run.
  3. Save the file then run the script in PowerShell.

Method 2:

  1. Rename scriptname.ps1 to scriptname.psm1 (PowerShell Module file)
  2. Run Import-Module cmdlet to import this module file.
            Import-Module filepath\scriptname.psm1
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
PowerShell
Edit|Remove
$File = $PhotosFolder.Files.Add($FullPath, $Picture.OpenRead(), $true) 
$ImagePath = $Web.Url + "/" + $File.Url  
$profiles =$profileManager.GetEnumerator() 
Foreach( $up in $profiles ) 
{ 
    If(($up["PictureURL"].Value -eq "") -or ($up["PictureURL"].Value -eq $null) ) 
    { 
        Write-host "Set picture for "$up.displayname 
        #Get user profile and change the Picture URL value 
        $up["PictureURL"].Value = $ImagePath 
        $up.Commit() 
    } 
    Else 
    { 
        $DisPlayName = $up.DisplayName 
        Write-warning  "$DisPlayName already has the picture."}}

Examples

Example 1: Get help about Set-OSCSPUserPhoto
Command: Get-Help Set-OSCSPUserPhoto -Full
Screenshot:
 
Example 2: Set default PictureUrl for users on site "http://win-lfseeatt8jr:18926/sites/test2"
Command: Set-OSCSPUserPhoto -SiteURL "http://win-lfseeatt8jr:18926/sites/test2" -PhotoPath "C:\Users\Administrator\Desktop\User.jpg" -Overwrite
Screenshot:
 
Note
If there is picture with the same name in the picture library, you can use "-Overwrite" to overwrite the picture.

Prerequisite

Windows PowerShell 2.0
Windows Server 2008R2

Additional Resources

Technical Resource:
Get-SPSite
http://technet.microsoft.com/en-us/library/ff607950.aspx