# export list fields $webUrl = "http://team/workgroups/DEMOSHAREDSERVICECENTRE/comms02" $listName = "VIPS" $attrs2delete = New-Object "System.Collections.Generic.List[string]" $("SourceID", "ColName", "RowOrdinal", "Version", "Group")|%{$attrs2delete.Add($_)} $allattrs = New-Object "System.Collections.Generic.List[string]" $w = get-spweb $webUrl $l = $w.Lists.TryGetList($listName) $flds = $l.Fields |?{-not $_.FromBaseType} $xmlFilePath = "C:\temp\Script-SiteColumns.xml" #Create Export Files New-Item $xmlFilePath -type file -force #Export Site Columns to XML file Add-Content $xmlFilePath "" Add-Content $xmlFilePath "`n" foreach($fld in $flds){ Add-Content $xmlFilePath $fld.SchemaXml Add-Content $xmlFilePath "`n" } Add-Content $xmlFilePath "" $xmlDoc = New-Object System.Xml.XmlDocument $xmlDoc.Load($xmlFilePath) $nodes = $xmlDoc.SelectNodes("//Fields/Field") $cnt = 1 foreach($node in $nodes){ "Processing node $($cnt)" $type = $node.SelectSingleNode("@Type").Value if($type -eq "Lookup") { $node.ParentNode.RemoveChild($node) } else { $attrs = $node.Attributes|?{$true}|%{$_} $attrs|%{ $attrName = $_.Name if(!$allattrs.Contains($attrName)) { $allattrs.Add($attrName)} if($attrs2delete.Contains($attrName)){ "Removing: $($attrName)" $node.Attributes.Remove($_) } $gr = $xmlDoc.CreateAttribute("Group") $gr.Value = "COMMS Request" $node.Attributes.Append($gr) } } $cnt++ } $xmlDoc.Save($xmlFilePath)