Skip to content

Instantly share code, notes, and snippets.

@jstangroome
Created February 12, 2014 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jstangroome/8951543 to your computer and use it in GitHub Desktop.
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/
#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