MOSS MVP

I've moved my blog to http://blog.falchionconsulting.com!. Please update your links. This blog is no longer in use--you can find all posts and comments at my new blog; I will no longer be posting to this site and comments have been disabled.

Monday, August 13, 2007

Set My Sites Naming Format

Update 9/25/2007: This command has been deprecated in favor of the gl-mysitesettings command.

Update 9/18/2007: I've modified this command so that it no longer manipulates the database directly. The content below has been updated to reflect the changes. T

his is another one of those for which there is no public API to manipulate programmatically. The command uses an internal method called CommitPersonalSiteSettings which is part of the UserProfileManager class (I had to use reflection to call this method but at least I'm not accessing the database directly). The previous version of this command required passing in the database server and database name for the SSP - now that I'm not hitting the database directly all that's necessary is the SSP name (and the naming format of course). I'm hoping that Microsoft will either make this method public or will create the ability to set these values via the existing properties:

   1: public override int Run(string command, StringDictionary keyValues, out string output)
   2: {
   3:     output = string.Empty;
   4:  
   5:     InitParameters(keyValues);
   6:  
   7:     string sspname = Params["sspname"].Value;
   8:     string format = Params["format"].Value;
   9:  
  10:     SiteNameFormat nameFormat = (SiteNameFormat)Enum.Parse(typeof(SiteNameFormat), format, true);
  11:  
  12:     UserProfileManager upm = new UserProfileManager(ServerContext.GetContext(sspname));
  13:     
  14:     MethodInfo commitPersonalSiteSettings =
  15:         upm.GetType().GetMethod("CommitPersonalSiteSettings",
  16:                                 BindingFlags.NonPublic | BindingFlags.Public |
  17:                                 BindingFlags.Instance | BindingFlags.InvokeMethod);
  18:  
  19:     commitPersonalSiteSettings.Invoke(upm,
  20:                     new object[]
  21:                         {
  22:                             upm.PersonalSiteInclusion, nameFormat, upm.PersonalSiteReaders, upm.IsPersonalSiteMultipleLanguage
  23:                         });
  24:  
  25:     return 1;
  26: }

The syntax of the command I created to do this can be seen below.

1. gl-setsitenamingformat

C:\>stsadm -help gl-setsitenamingformat

stsadm -o gl-setsitenamingformat

Sets the site naming format for the My Sites web application.

Parameters:
        -sspname <SSP name>
        -format <Username_CollisionError|Username_CollisionDomain|Domain_Username>

Here’s an example of how to set the site naming format:

stsadm –o gl-setsitenamingformat –sspname SSP1 -format Username_CollisionDomain

Please note that because this command uses an internal only method directly it could, according to Microsoft, put your environment into an un-supported state (though this is Microsoft's recommended approach over directly manipulating the database). Please make sure you understand what the command is doing and what your support options with Microsoft are.

5 comments:

Jeff said...

Great stuff, Gary. Thanks for documenting and posting your commands. I saw several that will be of use to me.

Anonymous said...

Hi Gary,I want to create , delete and recreate Mysite using stsadm command but once i delete mysite after that i could not create mysite.any solution pls.
thanks

Gary Lapointe said...

Are you getting an error? You should be able to just create the site using the stsadm createsite command - just make sure you have the naming convention correct and that you use the correct site template (note that it's generally not recommended to create my sites this way - it's better to let the user do it via the browser).

David Tappan said...

Gary, I this is a bit off topic, but a search for an answer brought me here, so I'll ask in case you know: We use pseudo-random strings here for usernames for security purposes, and don't want them revealed in the URL for My Sites. Is there any way to get My Site URLs to generate according to some other rule, like firstname.lastname?

Gary Lapointe said...

David - I only looked into this briefly but so far as I can tell there doesn't appear to be any way to do it. I thought that perhaps pre-setting the Personal Site profile property field might work as the code that builds the site looks in this field but there's probably some piece somewhere that I overlooked as pre-setting it made no difference. One thing I didn't try was to pre-create the site and then set the Personal Site field to see if that was sufficient to handle the mapping (there's more to do then just create the site and I just didn't have time to dig into it).