MisUszatek
asked on
Error messages when creating site columns from xml file
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:
When I run the script I get the following errors:
How do I make this work?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi
did you change line 37 to have the name of your SharePoint server ?
Regards
Joe
did you change line 37 to have the name of your SharePoint server ?
Regards
Joe
ASKER
I figured out my original problem - I had a typo in my xml file. Thank you very much for your help - very much appreciated!
ASKER
Open in new window
Is this a problem with the script or my environment?