Solved

PictureURL

Posted on 2011-09-13
10
411 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
  • 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
 

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Microsoft SharePoint Foundation 2010 and Microsoft SharePoint Server 2010 do not offer the option to configure the location of the SharePoint diagnostic trace log files during installation.  This can, however, be configured through Central Administr…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now