I’ve been working quite a bit with SharePoint 2010 lately and have written a number of PowerShell scripts that I think will be useful to folks. This is the first of these.
This script connects to the User Profile managed service application and iterates through all of the properties that have been configured dumping the result to XML. The script additionally pulls in any mappings to active directory.
I’m currently working on a script that will import this XML and update the properties accordingly. I hope to post that soon as well.
#Define our configuration. This is the name you gave the import connection to AD $url = "http://sharepoint.vallery.net/"; $connectionName = "Profile Sync"; #Setup our SharePoint objects $site = Get-SPSite $url; $serviceContext = Get-SPServiceContext($site); $upManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($serviceContext); $syncConnection = $upManager.ConnectionManager[$connectionName]; #This is a collection of mappings to AD that we will use later $pmc = $syncConnection.PropertyMapping; #This is a collection of all of the properties which we will iterate $properties = $upManager.GetProperties(); # Create a new XML writer settings object $settings = New-Object system.Xml.XmlWriterSettings; $settings.Indent = $true; $settings.OmitXmlDeclaration = $false; $settings.NewLineOnAttributes = $true; # Create a new string writer to capture the output $sw = new-object System.IO.StringWriter; # Create a new XmlWriter $writer = [system.xml.XmlWriter]::Create($sw, $settings); #Start the document and add the root node $writer.WriteStartDocument(); $writer.WriteStartElement("properties"); #Iterate through the properties foreach ($item in $properties); { #Create the property element $writer.WriteStartElement("property"); #Add in the fields as attributes $writer.WriteAttributeString("Name", $item.Name); $writer.WriteAttributeString("DisplayName",$item.DisplayName); $writer.WriteAttributeString("ManagedPropertyName",$item.ManagedPropertyName); $writer.WriteAttributeString("Type",$item.Type); $writer.WriteAttributeString("ChoiceList",$item.ChoiceList); $writer.WriteAttributeString("Description",$item.Description); $writer.WriteAttributeString("URI",$item.URI); $writer.WriteAttributeString("IsSystem",$item.IsSystem); $writer.WriteAttributeString("AllowPolicyOverride",$item.AllowPolicyOverride); $writer.WriteAttributeString("IsUserEditable",$item.IsUserEditable); $writer.WriteAttributeString("IsAdminEditable",$item.IsAdminEditable); $writer.WriteAttributeString("IsImported",$item.IsImported); $writer.WriteAttributeString("Length",$item.Length); $writer.WriteAttributeString("IsMultivalued",$item.IsMultivalued); $writer.WriteAttributeString("ChoiceType",$item.ChoiceType); $writer.WriteAttributeString("DefaultPrivacy",$item.DefaultPrivacy); $writer.WriteAttributeString("UserOverridePrivacy",$item.UserOverridePrivacy); $writer.WriteAttributeString("IsReplicable",$item.IsReplicable); $writer.WriteAttributeString("PrivacyPolicy",$item.PrivacyPolicy); $writer.WriteAttributeString("DisplayOrder",$item.DisplayOrder); $writer.WriteAttributeString("IsColleagueEventLog",$item.IsColleagueEventLog); $writer.WriteAttributeString("IsAlias",$item.IsAlias); $writer.WriteAttributeString("IsSearchable",$item.IsSearchable); $writer.WriteAttributeString("IsUpgrade",$item.IsUpgrade); $writer.WriteAttributeString("IsUpgradePrivate",$item.IsUpgradePrivate); $writer.WriteAttributeString("IsVisibleOnEditor",$item.IsVisibleOnEditor); $writer.WriteAttributeString("IsVisibleOnViewer",$item.IsVisibleOnViewer); $writer.WriteAttributeString("IsTaxonomic",$item.IsTaxonomic); $writer.WriteAttributeString("Separator",$item.Separator); $writer.WriteAttributeString("MaximumShown",$item.MaximumShown); $writer.WriteAttributeString("IsSection",$item.IsSection); $writer.WriteAttributeString("IsRequired",$item.IsRequired); $writer.WriteAttributeString("SubtypeName",$item.SubtypeName); #Look up any AD mappings in the PropertyManagerCollection and include them $writer.WriteAttributeString("IsImport",$pmc.Item($item.Name).IsImport); $writer.WriteAttributeString("IsExport",$pmc.Item($item.Name).IsExport); $writer.WriteAttributeString("DataSourcePropertyName",$pmc.Item($item.Name).DataSourcePropertyName); $writer.WriteAttributeString("OriginalDataSourcePropertyName",$pmc.Item($item.Name).OriginalDataSourcePropertyName); $writer.WriteAttributeString("AssociationName",$pmc.Item($item.Name).AssociationName); $writer.WriteAttributeString("Connection",$pmc.Item($item.Name).Connection.DisplayName); $writer.WriteEndElement(); } #Finish up $writer.WriteEndElement(); $writer.WriteEndDocument(); $writer.Flush(); $writer.Close(); #Capture the output into a string $result = $sw.ToString(); # Write the XML out Write-Output $result;
And here is an example of the XML output:






Great job! (I commented the wrong post before)
One thing I notices is that on the for each there is an “;” before the body of the loop.
Did you get to create the import? I want to export a list with some custom properties and then use the import on each new installation.
I run this script and got an xml format output but also 63 repetitions of the errors below. Does that mean there where 63 properties that werent exported?
Thank you!
You cannot call a method on a null-valued expression.
At line:76 char:54
+ $writer.WriteAttributeString(“IsImport”,$pmc.Item <<<< ($item.Name).IsImport);
+ CategoryInfo : InvalidOperation: (Item:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:77 char:54
+ $writer.WriteAttributeString("IsExport",$pmc.Item <<<< ($item.Name).IsExport);
+ CategoryInfo : InvalidOperation: (Item:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:78 char:68
+ $writer.WriteAttributeString("DataSourcePropertyName",$pmc.Item <<<< ($item.Name).DataSourcePropertyName);
+ CategoryInfo : InvalidOperation: (Item:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:79 char:76
+ $writer.WriteAttributeString("OriginalDataSourcePropertyName",$pmc.Item <<<< ($item.Name).OriginalDataSourcePropertyName);
+ CategoryInfo : InvalidOperation: (Item:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:80 char:61
+ $writer.WriteAttributeString("AssociationName",$pmc.Item <<<< ($item.Name).AssociationName);
+ CategoryInfo : InvalidOperation: (Item:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:81 char:56
+ $writer.WriteAttributeString("Connection",$pmc.Item <<<< ($item.Name).Connection.DisplayName);
+ CategoryInfo : InvalidOperation: (Item:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Actually there were 63 properties exported. Maybe the error is when looking at the mapping ?
I never got around to do the import although it’s something I’d like to do. It’s not really needed right now for what I’m working on.
Not sure about the errors. I’d have to check but I would guess that those values are null for whatever property you are exporting. Do you still get the XML out?
@jvallery
Yes, in not as an XML file, but in the out put (I just copy/paste the result, it’s not a problem to save it to an xml file directly)
Thanks for the answer!