Link to home
Start Free TrialLog in
Avatar of MisUszatek
MisUszatekFlag for United States of America

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:

[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)
}

Open in new window


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

Open in new window


How do I make this work?
ASKER CERTIFIED SOLUTION
Avatar of Joe Klimis
Joe Klimis
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MisUszatek

ASKER

I got the following error when running the script:

You cannot call a method on a null-valued expression.
At line:51 char:58
+     $fieldXMLString = $s.SiteColumns.Field.OuterXml.ToString <<<< ()
    + CategoryInfo          : InvalidOperation: (ToString:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
Exception calling "AddFieldAsXml" with "1" argument(s): "Root element is missing."
At line:52 char:31
+     $rootWeb.Fields.AddFieldAsXml <<<< ($fieldXMLString) 
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Open in new window


Is this a problem with the script or my environment?
Hi

did you change line 37 to have the name of your SharePoint server ?

Regards
Joe
I figured out my original problem - I had a typo in my xml file. Thank you very much for your help - very much appreciated!