Created
June 22, 2016 23:17
-
-
Save ayseff/cedd8ce72ac0e0db8d8ad10db6a973cb to your computer and use it in GitHub Desktop.
Remove Duplicates From packages.config
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
$path = "<some path>" | |
cls | |
$files = gci -Recurse -Path $path -Include packages.config | |
foreach($file in $files) { | |
[xml]$doc = $file | Get-Content | |
$dups = $doc.packages.package | Group-Object -Property id | Where-Object Count -GT 1 | Select Name, Count | |
foreach($dup in $dups) { | |
for($i=1; $i -le $dup.Count -1; $i++) { | |
$name = $dup.Name | |
$xpath = "//package[@id='$name']" | |
$node = $doc.SelectNodes($xpath).Item(1) | |
$node.ParentNode.RemoveChild($node) | |
} | |
} | |
$doc.Save($file.FullName) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment