I'm working on a Sharepoint 2010 site. I am trying to run this script from a website in order to create an xml containing info on my site columns.
$sourceWeb = Get-SPWeb http://farmstuff:1284
$xmlFilePath = "C:\Users\User\Scripts\Script-SiteColumns.xml"
#Create Export Files
New-Item $xmlFilePath -type file -force
#Export Site Columns to XML file
Add-Content $xmlFilePath "<?xml version=`"1.0`" encoding=`"utf-8`"?>"
Add-Content $xmlFilePath "`n<Fields>"
$sourceWeb.Fields | ForEach-Object {
if ($_.Group -eq "Custom Columns") {
Add-Content $xmlFilePath $_.SchemaXml
}
}
Add-Content $xmlFilePath "</Fields>"
$sourceWeb.Dispose()
And I get the following error:
An error occurred while enumerating through a collection: Exception has been thrown by the target of an invocation..
At C:\Users\User\Scripts\get-sitecolumns.ps1:10 char:5
+ <<<< %sourceWeb.Fields | ForEach-Object {
+ CategoryInfo : InvalidOperation: (Microsoft.Share...on+SPEnumerator:SPEnumerator) [], Runtime Exception
+ FullyQualifiedErrorId: BadEnumeration
Any help would be appreciated! I am not too familiar with Sharepoint or Powershell nuances yet. Thanks.
Edit:
<Field ID="{3C0E9E00-8FCC-479f-9D8D-3447CDA34C5B}" Name="OtherAddressCountry" StaticName="OtherAddressCountry" SourceID="http://schemas.microsoft.com/sharepoint/v3" DisplayName="Other Address Country" Group="Core Contact and Calendar Columns" Type="Text" Sealed="TRUE" AllowDeletion="TRUE" />
<Field ID="{9EBCD900-9D05-46c8-8F4D-E46E87328844}" Name="Categories" StaticName="Categories" SourceID="http://schemas.microsoft.com/sharepoint/v3" DisplayName="Categories" Group="Base Columns" Type="Text" Sealed="TRUE" AllowDeletion="TRUE" />
$web.Fields | % { $_.SchemaXml }alone works? In fact, I'm suspecting you have a unknown file type. This line should also fail in this case. – Steve B Jul 19 '12 at 14:43$sourceWeb.Fields[2]or$sourceWeb.Fields[2].IDif the former fail. If you are lucky, you will find the ID of the Field that is causing the issue. Starting with this ID, you will be able to search the faulty field. Probably a custom feature. I suggest you to use Notepad++ and do a search within all files of the 14 hives of kind xml, with the found ID as pattern. If I'm right, you'll find a<Field ID="xxx" />. Please post its declaration then. – Steve B Jul 19 '12 at 15:16