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.

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:

 1public 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.

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.