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"
$ie.Navigate($MySiteSettingsPage)

#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")
$Button.click()
Sleep -seconds 2
Stop-Process -Name iexplore
Advertisements

One comment

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s