Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ayseff/cedd8ce72ac0e0db8d8ad10db6a973cb to your computer and use it in GitHub Desktop.
Save ayseff/cedd8ce72ac0e0db8d8ad10db6a973cb to your computer and use it in GitHub Desktop.
Remove Duplicates From packages.config
$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