-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsonarqube-guid.ps1
30 lines (29 loc) · 976 Bytes
/
sonarqube-guid.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$paths = Get-ChildItem -Path $PSScriptRoot -include *.csproj -Recurse
$projectGuids = @()
foreach ($pathobject in $paths) {
$path = $pathobject.fullname
$doc = New-Object System.Xml.XmlDocument
$doc.Load($path)
$node = $doc.SelectSingleNode("//Project/PropertyGroup/ProjectGuid")
if (!$node) {
$child = $doc.CreateElement("ProjectGuid")
$child.InnerText = [guid]::NewGuid().ToString().ToUpper()
$node = $doc.SelectSingleNode("//Project/PropertyGroup")
$node.AppendChild($child)
$doc.Save($path)
$projectGuids += $child.InnerText.ToUpper()
}
elseif($projectGuids.Contains($node.InnerText)){
Write-Host "Duplicate found"
$node.InnerText = [guid]::NewGuid().ToString().ToUpper()
$doc.Save($path)
$projectGuids += $node.InnerText.ToUpper();
}
else{
$projectGuids += $node.InnerText;
}
}
foreach($g in $projectGuids | Sort-Object)
{
Write-Host $g
}