Solved

PictureURL

Posted on 2011-09-13
10
451 Views
Last Modified: 2012-05-12
Having 3 webapps:  WebApp1 (CountryA)  + WebApp2 (CountryB) - and a "common" Mysite

I would like that human resource dept. in each country maintain they "own" pictures of the employes by a picture library on each countrys site...

Right now both CountryA and CountryB and the Mysite looks in the picturelibrary that resides on CountryA

I have done by this powershell script:

#My Site URL
$mySiteUrl = "http://mysite/"
 
#The part of the picture URL you are trying to find
$pictureLibUrl = "http://countryA/employesspictures"

#The internal name for PictureURL
$upPictureURLAttribute = "PictureURL"
#The internal name for Login
$LoginAttribute = "AccountName"

 
#Get site objects and connect to User Profile Manager service
$site = Get-SPSite $mySiteUrl
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$profiles = $profileManager.GetEnumerator()
 
foreach ($userProfile in $profiles) {

  $userLogin = $userProfile[$LoginAttribute].Value.Split('\')[1]
  $newPictureURL = $pictureLibUrl + $userLogin + ".jpg"
  $userProfile[$upPictureURLAttribute].Value = $newPictureURL
  $userProfile.Commit()

  write-host "User: " $userLogin " Picture: " $newPictureURL
} 

Open in new window


How can I accomplish that the common "Mysite" should look in both CountryA and CountryB and that CountryA should look in http://countryA/employepictures AND CountryB should look in http://countryB/employepictures  ??


Hope it makes sense....  
0
Comment
Question by:Aarsleff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 16

Expert Comment

by:quihong
ID: 36533488
You can't have it "look in both". You need to add some logic based on another profile field (i.e. office location), and then set the pictureURL field.
0
 

Author Comment

by:Aarsleff
ID: 36533938
Ok...do you have and powershell example (I'm not a programmer)

Btw... The CountryA and CountryB are in different OU's in AD - but both gets imported by the UPS application in SP    

It's to achieved that the Users in CountryA don't have access to CountryB and vice versa.... of course they all have access to the mysite webapp
0
 
LVL 38

Accepted Solution

by:
Justin Smith earned 500 total points
ID: 36535583
I've never seen this done, not even sure it's possible out of the box.  I'm anxious to see if there will be a solution to this.

Can't the HR people just upload photos directly to the Photo Library on the MySite host site?
0
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

Author Comment

by:Aarsleff
ID: 36536178
Oh..yes... that could be a solution ...will the employees pictures then be displayed on each country webapp if one search for a person within the countryA...?? (the people search has to function as a phonebook.. )
0
 
LVL 38

Expert Comment

by:Justin Smith
ID: 36536329
As long as both web apps are subscribed to the User Profile App, yes.
0
 

Author Comment

by:Aarsleff
ID: 36536440
They are ... so that's the solution then... thanks...  ;)

So I'll just change the script to?:

#My Site URL
$mySiteUrl = "http://mysite/"
 
#The part of the picture URL you are trying to find
$pictureLibUrl = "[b]http://Mysite/employeespictures[/b]"

#The internal name for PictureURL
$upPictureURLAttribute = "PictureURL"
#The internal name for Login
$LoginAttribute = "AccountName"

Open in new window

0
 
LVL 16

Expert Comment

by:quihong
ID: 36538004
I am a little confused on the ultimate goal here.

It sounds like you're okay now to use one photo library for all your employee photos regardless of country. This would be the simplest route. Just make sure that everyone has read access to the library so the photo is correctly displayed in the people search result. Your HR department would have Contributor rights to upload photos.

I would suggest you check if the photo exist before setting it. See code.
foreach ($profile in $upm)
{
   $photoUrl = $portalurl + "/employee photos/" + $profile["EmployeeID"].Value + ".jpg"
   $photoFile = $portalweb.GetFile($photoUrl)

   if($photoFile.Exists) {
      $profile["PictureURL"].Value = $portalurl + "/employee photos/" + $profile["EmployeeID"].Value + ".jpg"
      $profile.Commit()
   }
   else {
      $profile["PictureURL"].Value = $null
      $profile.Commit()
   } 
}

Open in new window

0
 

Author Comment

by:Aarsleff
ID: 36538473
The goal are to keep it simple... By that there's no problem for both HR departments (or more countries later) to have access to the http://mysite/employeepictures with the role and All authentificated users to have read access...;)


I move the picture lib to mysite root and just replace the foreach code block with yours and Run the script?
0
 
LVL 16

Expert Comment

by:quihong
ID: 36539409
Pretty much. Please test in a non-production env.

You would probably want to schedule the script.
0
 

Author Comment

by:Aarsleff
ID: 36540649
Thanks ... :D

Am I wrong when i say that the variables in your "fore each" block differs from my original script...? (I am a total NooB to code and syntax..)

You have:

$photoUrl = $portalurl + "/employee photos/" + $profile["EmployeeID"].Value + ".jpg"
   $photoFile = $portalweb.GetFile($photoUrl)

if($photoFile.Exists) {
$profile["PictureURL"].Value = $portalurl + "/photos/" + $profile["EmployeeID"].Value + ".jpg"
$profile.Commit()
}

Open in new window


Could you please adjust it to the complete script code ?

#My Site URL
$mySiteUrl = "http://mysite/"

#The part of the picture URL you are trying to find
$pictureLibUrl = "http://countryA/employesspictures"

#The internal name for PictureURL
$upPictureURLAttribute = "PictureURL"
#The internal name for Login
$LoginAttribute = "AccountName"


#Get site objects and connect to User Profile Manager service
$site = Get-SPSite $mySiteUrl
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$profiles = $profileManager.GetEnumerator()

<!--foreach ($userProfile in $profiles) {

$userLogin = $userProfile[$LoginAttribute].Value.Split('\')[1]
$newPictureURL = $pictureLibUrl + $userLogin + ".jpg"
$userProfile[$upPictureURLAttribute].Value = $newPictureURL
$userProfile.Commit()-->


foreach ($profile in $upm)
{
$photoUrl = $portalurl + "/employee photos/" + $profile["EmployeeID"].Value + ".jpg"
$photoFile = $portalweb.GetFile($photoUrl)

if($photoFile.Exists) {
$profile["PictureURL"].Value = $portalurl + "/photos/" + $profile["EmployeeID"].Value + ".jpg"
$profile.Commit()
}
else {
$profile["PictureURL"].Value = $null
$profile.Commit()
}
}

write-host "User: " $userLogin " Picture: " $newPictureURL
}

Open in new window


0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SharePoint Designer 2010 has tools and commands to do everything that can be done with web parts in the browser, and then some – except uploading a web part straight into a page that is edited in SPD. So, can it be done? Scenario For a recent pr…
We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Da…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question