The project that I'm currently on has a test environment in which many configurations were made to the user profile properties settings. I just began the process of building out their production environment and was faced with a minor issue - how do I get all the settings that have been applied to the test environments profile properties migrated to the production environment in a reliable and repeatable way? I took a look around and remembered that I already had a command to dump out the profile property settings into an XML file - gl-enumprofileproperties - so now I just needed another command that could take the output from my previous command and use it to import those settings into another farm.
Fortunately this turned out to be very easy (with one minor caveat). I called this new command gl-importprofileproperties. First lets take a look at a sample of the output generated by the gl-enumprofileproperties command:
As you can see from the above XML there's really not much to - it's just a dump of all the properties (including read-only properties) that are found on the Microsoft.Office.Server.UserProfiles.Property object. So, importing these settings back in is a simple matter of looping through the Property XML elements shown above, finding the right Property object, and then set each property value. Here's the core code that accomplishes this:
So I mentioned that there was one caveat that I discovered - turns out that it's more of a bug. If you do an export and then immediately import using this command you will likely get an exception when it comes to importing the SPS-ProxyAddresses field. Here's the specific exception you will see:
Progress: Setting properties for 'SPS-ProxyAddresses'. Progress: Updating import mapping for 'SPS-ProxyAddresses'. ERROR: The character length specified is invalid. at Microsoft.Office.Server.UserProfiles.Property._TypeValidate(DBAction action) at Microsoft.Office.Server.UserProfiles.Property._TypeValidate(IEnumerable enumAddPropertyList, IEnumerable enumUpdatePropertyList) at Microsoft.Office.Server.UserProfiles.Property._Update(SRPSite site, IEnumerable enumAddPropertyList, IEnumerable enumUpdatePropertyList, IEnumerable enumRemovePropertyList) at Microsoft.Office.Server.UserProfiles.Property.Commit() at Lapointe.SharePoint.STSADM.Commands.UserProfiles.ImportProfileProperties.Execute(String command, StringDictionary keyValues, String& output)
So what's the deal with this? Simple - it's a bug. Here's another way you can expose the bug - via the browser go to your user profile properties page and then click to edit the SPS-ProxyAddresses field. Then, on the edit screen, simply click the "OK" button without making any changes - you'll get the following error:
The problem is that this particular field is a multi-value field which can only have a maximum length of 400 but the field length is set to 2048 and because it's a built-in system field we can't change the length to fix it and therefore we can't change anything about the property.
So, to deal with this I made it so that my code simply dumps out errors like this and moves on to the next item - but you will see this error every time you attempt an import - there's no way around it (you can't change the length of an existing field so you can't fix the problem to prevent the error).
The help for the command is shown below:
C:\>stsadm -help gl-importprofileproperties stsadm -o gl-importprofileproperties Imports user profile properties using the output of gl-enumprofileproperties. Parameters: -inputfile <file to import results from> [-sspname <name of the SSP>] [-removemissing (removes properties missing from the import)
The following table summarizes the command and its various parameters:
|Command Name||Availability||Build Date|
|gl-importprofileproperties||MOSS 2007||Released: 8/14/2008
|Parameter Name||Short Form||Required||Description||Example Usage|
|sspname||ssp||No||The name of the SSP that the profile properties are associated with. If omitted the default SSP will be used.||-sspname SSP1
|inputfile||input||Yes||The path to the XML file to use for import. The XML must correspond to the XML generated by the gl-enumprofileproperties command.||-inputfile c:\properties.xml
|removemissing||rm||No||Deletes any properties that were not defined in the import file. It's recommended that if you use this flag that you first backup the existing properties using the gl-enumprofileproperties command.||-removemissing
The following is an example of how to import user profile properties:
stsadm -o gl-importprofileproperties -inputfile c:\properties.xml
Update 8/22/2008: I fixed a few bugs that were preventing the importing of new properties. I also fixed it so that data mappings can be reassigned without having to run multiple times. I also added support for setting the display order and for removing properties that do not exist in the import by passing in the -removemissing parameter.