Home
> Work > Updating User Profile Properties via PowerShell (PictureURL)–SharePoint 2010 #in #SP2010
Updating User Profile Properties via PowerShell (PictureURL)–SharePoint 2010 #in #SP2010
I have recently had reason to update the PictureURL property value via PowerShell in SharePoint 2010 for all users in the system.
As a result, I wrote the following PowerShell script to update the property value using string replace.
Although not generic code, I shall be using this again as a starting base to update any property in future.
You will ideally need to run this on the server with an account with the appropriate permissions to update all user profiles.
1 #Set up default variables 2 3 #My Site URL 4 $mySiteUrl = "http://mysite/" 5 6 #The part of the picture URL you are trying to find 7 $currentURLValue = "http://mypersonalsite" 8 9 #The value that will replace the above 10 $newURLValue = "http://mysite:80" 11 12 #The internal name for PictureURL 13 $upPictureURLAttribute = "PictureURL" 14 15 #Get site objects and connect to User Profile Manager service 16 $site = Get-SPSite $mySiteUrl 17 $context = Get-SPServiceContext $site 18 $profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context) 19 $profiles = $profileManager.GetEnumerator() 20 21 foreach ($userProfile in $profiles) { 22 23 if ($userProfile[$upPictureURLAttribute] -ne '') { 24 25 $newPictureURL = $userProfile[$upPictureURLAttribute].toString() 26 $newPictureURL = $newPictureURL.Replace($currentURLValue, $newURLValue) 27 28 write-host "Before: " $userProfile[$upPictureURLAttribute].toString() " | After: " $newPictureURL 29 30 #Get user profile and change the value - uncomment the lines below to commit the changes 31 #$userProfile[$upPictureURLAttribute].Value = $newPictureURL 32 #$userProfile.Commit() 33 34 } 35 36 } 37
Categories: Work
Tags: PictureURL, SharePoint 2010, User Profile Properties, User Profile Service
Leave a Reply Cancel reply
Tags
Android
Business Intelligence
C#
Certification
Client Object Model
CodePlex
Development
EPM
Form Services 2010
François Souyri
InfoPath 2010
iOS
iPad
iPhone
JavaScript
JQuery
Microsoft Word
Mobile Application
MOSS 2007
Office 365
Office 2010
PowerShell
Project
Project 2010
Project 2013
Project Conference 2012
Project Management
Project Online
Project Server
Project Server 2007
Project Server 2010
Project Server 2013
PS2010
SharePoint
SharePoint 2010
SharePoint 2013
SharePoint Designer 2010
SharePoint Online
SPF 2010
TechEd Europe 2012
Visual Studio 2010
Web Part
Windows 7
Workflow
WSS 3.0
Top Posts
- #ProjectServer 2013 White Paper
- Useful JavaScript Function: PreSaveAction #SP2010 #SharePoint #PS2010 #ProjectServer #in
- Clearing the SharePoint Designer 2007 / 2010 Cache
- Populate a drop-down list with SharePoint list values
- Excel formulas not auto calculating but F9 still works #in
- Embedding PDF files with the Content Editor Web Part #SP2010 #SP2013 #MSProject
- Programmatically setting a field to hidden within a Content Type #SharePoint #SP2010 #in
- Security Validation Issue - Form Services issue with SP1+June 2011 CU (Release 2) #in #SP2010 #SharePoint #MSProject #ProjectServer
- SharePoint and Document Versioning within Word.
- Custom Navigation in a SharePoint Hosted App in SharePoint 2013
Blogroll
Archives
Blog Stats
- 228,623 hits
Great post! Regrettably, I keep running into:
New-Object : Exception calling “.ctor” with “1″ argument(s): “Object reference not set to an instance of an object.”
At line:1 char:29
+ $profileManager = New-Object <<<< Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
… and yes I load the assemblies.
Any ideas?
Blaalyn, this article was helpful for me:
http://blogs.technet.com/b/speschka/archive/2010/02/22/no-user-profile-application-available-mystery-in-sharepoint-2010.aspx
if you encounter the issue above, i believe it means that your account doesn’t have the right permissions (maybe on the User Profile DB?). Try running as the farm account.