Skip to content

Instantly share code, notes, and snippets.

@Fazzani
Created November 16, 2020 10:47
Show Gist options
  • Select an option

  • Save Fazzani/d21ce89f736566f8f5624f26bf59e299 to your computer and use it in GitHub Desktop.

Select an option

Save Fazzani/d21ce89f736566f8f5624f26bf59e299 to your computer and use it in GitHub Desktop.

Revisions

  1. Fazzani created this gist Nov 16, 2020.
    40 changes: 40 additions & 0 deletions sonarqube-create-project-guids.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    # Project Guid Generator
    # Creator: Unknown
    # Editor: Isaac martinez
    # Notes: A requirement of SonarCloud/SonarQube is that all projects have a unique
    # ProjectGuid. This script takes care of that. This script will recursively
    # look for projects in subfolders and apply the necessary changes.
    # Version Date: 05/19/2020

    $paths = Get-ChildItem -Path $PSScriptRoot -include *proj -Recurse
    Write-Host $paths.count "project(s) found"
    $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")
    if (!$node){
    Write-Host "Error:" $path "- Project file is missing //Project/PropertyGroup node"
    }
    else {
    $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;
    Write-Host $path "already has a valid ProjectGuid"
    }
    }