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
Advertisement
Categories: Work
Tags: PictureURL, SharePoint 2010, User Profile Properties, User Profile Service
Leave a Reply Cancel reply
Recommended Podcast
Archives
Join 2,193 other subscribers
Tags
.NET Android Azure Business Intelligence C# Calculated Column Certification Chris Clements Client Object Model CodePlex conference CU Development EPM Excel Form Services 2010 François Souyri InfoPath 2010 Information Rights Management iOS iPad iPhone IRM ISCLondon JavaScript JQuery Microsoft Word Mobile Application MOSS 2007 Office 365 Office 2010 Other Performance PowerBI PowerShell Presentation Project Project 2010 Project 2013 Project Conference 2012 Project Management Project Managment Project Online Project Server Project Server 2007 Project Server 2010 Project Server 2013 PS2007 PS2010 Rights Management Server RMS Search SharePoint SharePoint 2010 SharePoint 2013 SharePoint 2016 SharePoint Designer 2010 SharePoint Online SharePoint Saturday UK SP.ClientContext.get_current() SP2010 SP2016 Speaking Engagements SPF 2010 sql server reporting services Supported File Types TechEd Europe 2012 Technical Preview visio Visual Studio 2010 Visual Web Part Web Part Windows 7 Workflow WSS 3.0Blog Stats
- 622,362 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.