Skip to content

Instantly share code, notes, and snippets.

@vaderj
Last active June 12, 2018 17:04
Show Gist options
  • Save vaderj/b0188a13e60cc6fc5354ec5c1b8ca3a4 to your computer and use it in GitHub Desktop.
Save vaderj/b0188a13e60cc6fc5354ec5c1b8ca3a4 to your computer and use it in GitHub Desktop.
#Set up default variables
#My Site URL
$mySiteUrl = "http://mysite/"
#The part of the picture URL you are trying to find
$currentURLValue = "http://mypersonalsite"
#The value that will replace the above
$newURLValue = "http://mysite:80"
#The internal name for PictureURL
$upPictureURLAttribute = "PictureURL"
#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) {
if ($userProfile[$upPictureURLAttribute] -ne '') {
$newPictureURL = $userProfile[$upPictureURLAttribute].toString()
$newPictureURL = $newPictureURL.Replace($currentURLValue, $newURLValue)
write-host "Before: " $userProfile[$upPictureURLAttribute].toString() " | After: " $newPictureURL
#Get user profile and change the value - uncomment the lines below to commit the changes
#$userProfile[$upPictureURLAttribute].Value = $newPictureURL
#$userProfile.Commit()
}
$url = "http://intranet/"
$site = Get-SPSite $url
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$profiles = $profileManager.GetEnumerator()
while ($profiles.MoveNext()) {
$userProfile = $profiles.Current
$name = $userProfile.DisplayName
$phone = $userProfile["WorkPhone"]
$line = '{0};{1}' -f $name, $phone
write $line
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment