If users had created their personal sites, is it possible to change the My Site path to make the Url more user friendly(such as http://myspserver) ?
Yes, we can. It turns out quite easy, and we even don't need to move any personal sites.
1. Extend the web application to another IIS Web Site and then change AAM
So we can access the personal sites through http://myspserver
2. Change the user profile service "MySiteHostUrl" through PowerShell scripts
Add-PSSnapin Microsoft.Sharepoint.Powershell
$AnySiteCollectionUrl = "http://AnySPSite/"
$site = Get-SPSite $AnySiteCollectionUrl
$context = Get-SPServiceContext($site)
$pm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
Write-Host "previous My Site Host Url: " $pm.MySiteHostUrl -ForegroundColor Yellow;
$pm.MySiteHostUrl = ""
$pm.MySiteHostUrl = "http://myspserver/"
Write-Host "new My Site Host Url: " $pm.MySiteHostUrl -ForegroundColor Yellow;
$site.Dispose()
Write-Host "Finished! Press enter key to exit." -ForegroundColor Green
Read-Host
3. Change "PictureUrl" for all user profiles
Add-PSSnapin Microsoft.Sharepoint.Powershell
$AnySiteCollectionUrl = "http://AnySPSite/"
$patternToReplace = "http://spserver:800"
$patternToReplaceWith = "http://myspserver"
$site = Get-SPSite $AnySiteCollectionUrl
$context = Get-SPServiceContext($site)
$profileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
Write-Host "profileManager.Count: " $profileManager.Count -ForegroundColor Yellow;
$profiles = $profileManager.GetEnumerator()
foreach ($userProfile in $profiles) {
if($userProfile["PictureUrl"].Value -ne $null)
{
Write-Host "AccountName: " $userProfile["AccountName"].Value ", PictureUrl: " $userProfile["PictureUrl"].Value -ForegroundColor Yellow;
$oldUrl = $userProfile["PictureUrl"].Value
if($oldUrl -match $patternToReplace){
$userProfile["PictureUrl"].Value = $oldUrl.Replace($patternToReplace, $patternToReplaceWith)
$userProfile.Commit()
Write-Host "new PictureUrl: " $userProfile["PictureUrl"].Value -ForegroundColor Yellow;
}
}
}
$site.Dispose()
Write-Host "Finished! Press enter key to exit." -ForegroundColor Green
Read-Host
4. Done.
References:
This was very helpful. Thanks.
ReplyDeleteI had some difficulties running the code as user SP-Admin even though the user had the correct persmissions. I had to user SP-Farm account for this.
Also I had to remove the URL I was going to use as new MySiteHostURL from Alternate Access Mappings and reinsert it after the process.
Furthermore, the changes don't seem to get persisted correctly. I changed it, checked it an it worked. When I looked into the service application's properties a week later the MySiteHostURL was changed back to its original value. Any idea about that?
>>I had some difficulties running the code as user SP-Admin
DeleteI think you need db_owner rights of the sp config database and the user profile db
>>Also I had to remove the URL I was going to use as new MySiteHostURL from Alternate Access Mappings and reinsert it after the process
Sorry, I don't know the reason of it.
>>the changes don't seem to get persisted correctly
Not sure. May need to change the default url of "my site web application"
2 questions.
Delete1st: Does this work on SharePoint 2013 because that is what I am trying to use it on.
2nd: When I run the 1st script it returns the new site as the same as the previuous site URL.
What am I doing wrong? thanks
my script example
Add-PSSnapin Microsoft.Sharepoint.Powershell
$AnySiteCollectionUrl = "http://mysites.subdomain.mydomain.com/"
$site = Get-SPSite $AnySiteCollectionUrl
$context = Get-SPServiceContext($site)
$pm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
Write-Host "previous My Site Host Url: " $pm.MySiteHostUrl -ForegroundColor Yellow;
$pm.MySiteHostUrl = "mysites.mydomain.com"
$pm.MySiteHostUrl = "http://mysites.subdomain.mydomain.com/"
Write-Host "new My Site Host Url: " $pm.MySiteHostUrl -ForegroundColor Yellow;
$site.Dispose()
Write-Host "Finished! Press enter key to exit." -ForegroundColor Green
Read-Host
Hi Dave,
DeleteCould you try any other site url for "$AnySiteCollectionUrl"?
Thanks for responding Eric. I actually have tried multiple "$AnySiteCollectionUrl" with no luck. I have tried other combinations such as
Delete$pm.MySiteHostUrl = ""
$pm.MySiteHostUrl = "http://mysites.mydomain.com/"
$pm.MySiteHostUrl = "http://mysites.mydomain.com/"
$pm.MySiteHostUrl = "http://mysites.mydomain.com/"
Although the script returns results saying the site has been changed I don't see any differences on the site or central admin.
Thanks again for the response.
Dave,
DeleteI mean, you may try this one:
$AnySiteCollectionUrl = "http://www.subdomain.mydomain.com/"
$site = Get-SPSite $AnySiteCollectionUrl
......
Sorry my last communication was unclear but what I was trying to say was I have tried multiple $AnySiteCollectionUrl =
Deletefor examnple
$AnySiteCollectionUrl = "http://www.subdomain.mydomain.com/"
$AnySiteCollectionUrl = "http://www.subdomain2.mydomain.com/"
$AnySiteCollectionUrl = "http://www.subdomain3.mydomain.com/"
no luck.
Is this something that you have tried on SharePoint 2013?
Dave,
DeleteSorry, I haven't got chance to try that yet.
question:
ReplyDelete1. Does the user must first create his personal page and then it works? Or can I just install only SharePoint, and then enter the commands?
2. Can you please explain what steps I need to perform this: Extend the web application to another IIS Web Site and then change AAM
3. What is the AAM?