SharePoint 2010 – MySite Preferred Search Center Setting – Powershell

Due to the fact that MySite settings belongs to an internal class in SharePoint 2010 and no powershell cmdlet was able to edit the Preferred Search center setting for MySite, a little creative scripting was needed. Reusing and optimizing the Change Enterprise Key script made it possible.

I changed the visible parameter for IE and stopped the ie process afterwards, making it a cleaner script.

#–Setting Preferred Search center for MySite

#--Get the central admin URL
$CAUrl = (Get-spwebapplication -includecentraladministration | where {$_.IsAdministrationWebApplication}).Url
#-- Get the User Profile Service MySite settings page
$UPSID = ((Get-SPServiceApplication | Where-Object {$_.DisplayName -like "User Profile*"}).Id).Guid
$MySiteSettingsPage = $CAUrl + "_layouts/PersonalSites.aspx?ApplicationID=" + "$UPSID"
#-- Create MySite Preferred Search center value.
$MySiteUrl= (Get-SPWebApplication | Where-Object {$_.DisplayName -like "minside.*"}).Url
$MySiteSearch= $MySiteUrl +"soeg"

$ie = New-Object -ComObject "InternetExplorer.Application"

#wait for central Admin to load
while ($ie.ReadyState -ne 4)
sleep -Milliseconds 100
$PreferredSearchCenterBox = $ie.Document.getElementById("ctl00_PlaceHolderMain_txtboxSearchCenter")
$PreferredSearchCenterBox.value = $MySiteSearch
$Button = $ie.Document.getElementById("ctl00_PlaceHolderMain_btnOk")
Sleep -seconds 2
Stop-Process -Name iexplore

One comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.