Solved

PictureURL

Posted on 2011-09-13
10
444 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

I used to be SharePoint evangelist in our company, so my Outlook always full of questions about how to do this, or where I can find that. One day I found such an email with the following question: "how to attach 3-State workflow (one of the workflow…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 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