troubleshooting Question

Error messages when creating site columns from xml file

Avatar of MisUszatek
MisUszatekFlag for United States of America asked on
Microsoft SharePointPowershell
4 Comments1 Solution2637 ViewsLast Modified:
I am trying to use the solution from this post:
http://social.technet.microsoft.com/Forums/en-US/sharepointadminprevious/thread/f4378893-e807-49cd-a955-eeb15a77aa8e

My script looks like this:

[xml]$s = Get-Content NewColumns.xml
$siteColl = Get-SPSite -Identity "http://server/sites/projects/"
$rootWeb = $siteColl.RootWeb
$fields = $s.SelectNodes("/SiteColumns/Field")
$fields | Foreach-Object {
$fieldXMLString = $_.OuterXml.ToString()
$rootWeb.Fields.AddFieldAsXml($fieldXMLString)
}

When I run the script I get the following errors:

Cannot convert value "System.Object[]" to type "System.Xml.XmlDocument". Error: "The 'SiteColumns' start tag on line 2 does not match the end tag of 'Fie
ld'. Line 4, position 5."
At line:1 char:8
+ [xml]$s <<<<  = Get-Content NewColumns.xml
    + CategoryInfo          : MetadataError: (:) [], ArgumentTransformationMetadataException
    + FullyQualifiedErrorId : RuntimeException
 
You cannot call a method on a null-valued expression.
At line:4 char:25
+ $fields = $s.SelectNodes <<<< ("/SiteColumns/Field")
    + CategoryInfo          : InvalidOperation: (SelectNodes:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
You cannot call a method on a null-valued expression.
At line:6 char:39
+ $fieldXMLString = $_.OuterXml.ToString <<<< ()
    + CategoryInfo          : InvalidOperation: (ToString:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
Exception calling "AddFieldAsXml" with "1" argument(s): "Root element is missing."
At line:7 char:30
+ $rootWeb.Fields.AddFieldAsXml <<<< ($fieldXMLString)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

How do I make this work?
ASKER CERTIFIED SOLUTION
Joe Klimis
Security Application consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros