Last active
August 29, 2015 14:02
-
-
Save zplume/13b07f00273edb8f14d6 to your computer and use it in GitHub Desktop.
A PowerShell utility script that outputs C# code listing all custom fields in the RootWeb of a site collection (filtered by a field name prefix) as a set of static classes with constant string properties for Id and Name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$siteUrl = "http://site/collection/url" | |
$fieldPrefix = "ClientName_" | |
$outputPath = "c:\temp\Fields.cs" | |
$site = Get-SPSite $siteUrl | |
$fields = $site.RootWeb.Fields | |
$output = "" | |
$newLine = "`r`n" | |
$tab = "`t" | |
$fields | Sort InternalName | | |
Where { $_.InternalName -like "$fieldPrefix*" } | | |
ForEach { | |
$output += $("public static class " + $_.InternalName.Replace($fieldPrefix, "").Replace("_0", "TaxHTField") + $newLine) | |
$output += $("{" + $newLine) | |
$output += $($tab + "public const string Id = `"" + $_.Id + "`";" + $newLine) | |
$output += $($tab + "public const string InternalName = `"" + $_.InternalName + "`";" + $newLine) | |
$output += $("}" + $newLine + $newLine) | |
} | |
$output | Out-File $outputPath | |
$site.Dispose() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class AgeRange | |
{ | |
public const string Id = "12b9b899-04c2-47c5-bcf9-cf9ee5055099"; | |
public const string InternalName = "ClientName_AgeRange"; | |
} | |
public static class AgeRangeTaxHTField | |
{ | |
public const string Id = "29244be4-988e-454d-a1b3-e8f8c08317c8"; | |
public const string InternalName = "ClientName_AgeRange_0"; | |
} | |
public static class AnimationType | |
{ | |
public const string Id = "bf620570-8866-4334-a791-63635aaed4a2"; | |
public const string InternalName = "ClientName_AnimationType"; | |
} | |
public static class AnimationTypeTaxHTField | |
{ | |
public const string Id = "85cf3e96-858d-499c-958f-f7c58ddcd3aa"; | |
public const string InternalName = "ClientName_AnimationType_0"; | |
} | |
public static class Channel | |
{ | |
public const string Id = "d15f5cda-a4ea-4980-af8f-022556311f28"; | |
public const string InternalName = "ClientName_Channel"; | |
} | |
public static class ChannelTaxHTField | |
{ | |
public const string Id = "1b27d38c-19a6-4f6a-bb17-0bff2f037a54"; | |
public const string InternalName = "ClientName_Channel_0"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment