Created
February 12, 2014 07:50
-
-
Save jstangroome/8951543 to your computer and use it in GitHub Desktop.
A PowerShell script which removes all the unnecessary elements and attributes from a Team Build Process Template XAML file that have been added by the Workflow Designer. http://blog.stangroome.com/2014/02/12/effectively-comparing-team-build-process-templates/
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
#requires -version 3 | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory)] | |
[ValidateScript({ $_ | Test-Path -PathType Leaf })] | |
[string] | |
$Path, | |
[string] | |
$Destination = $Path | |
) | |
# ensure the path is fully qualified for use with $Doc.Save() | |
$Destination = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($Destination) | |
$Namespaces = @{ | |
xmlns = 'http://www.w3.org/2000/xmlns/' | |
mc = 'http://schemas.openxmlformats.org/markup-compatibility/2006' | |
} | |
$Doc = (Select-Xml -Path $Path -XPath / ).Node | |
$IgnorableValue = $Doc.DocumentElement.GetAttribute('Ignorable', $Namespaces.mc) | |
$IgnorablePrefixes = @() | |
if ($IgnorableValue) { | |
$IgnorablePrefixes = @($IgnorableValue -split '\s+') | |
} | |
foreach ($Prefix in $IgnorablePrefixes) { | |
$NamespaceUri = $Doc.DocumentElement.GetAttribute($Prefix, $Namespaces.xmlns) | |
$PrefixNamespaces = @{ $Prefix = $NamespaceUri } | |
# elements | |
Select-Xml -Xml $Doc -XPath "//$Prefix`:*" -Namespace $PrefixNamespaces | | |
Select-Object -ExpandProperty Node | | |
ForEach-Object { | |
$_.ParentNode.RemoveChild($_) | Out-Null | |
} | |
# attributes | |
Select-Xml -Xml $Doc -XPath "//*/@$Prefix`:*" -Namespace $PrefixNamespaces | | |
Select-Object -ExpandProperty Node | | |
ForEach-Object { | |
$_.OwnerElement.RemoveAttributeNode($_) | Out-Null | |
} | |
} | |
$Doc.Save($Destination) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment