functions/Update-CorrelationIDs.ps1
function Update-CorrelationIDs { <# .SYNOPSIS Updates all existing GUIDs with new GUIDs .DESCRIPTION Searches and replaces all "CorrelationId" GUIDs found in the .JSON file with new GUIDs .PARAMETER Path Specify the path to the .JSON file you want to update .EXAMPLE Update-CorrelationIDs -Path C:\myJsonRepo\exampleFile.json #> [CmdletBinding()] Param ( [Parameter(Mandatory=$true,Position=0)][string]$Path ) if (Test-Path $Path) { $json = Get-Content -Path $Path | ConvertFrom-Json foreach ($globalOperation in $json.globalOperations) { $globalOperation.correlationId = $globalOperation.correlationId -replace "\b[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}\b", (New-Guid) } foreach ($testOperation in $json.testOperations) { $testOperation.correlationId = $testOperation.correlationId -replace "\b[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}\b", (New-Guid) } foreach ($firstOperation in $json.firstOperations) { $firstOperation.correlationId = $firstOperation.correlationId -replace "\b[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}\b", (New-Guid) } foreach ($fastOperation in $json.fastOperations) { $fastOperation.correlationId = $fastOperation.correlationId -replace "\b[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}\b", (New-Guid) } foreach ($broadOperation in $json.broadOperations) { $broadOperation.correlationId = $broadOperation.correlationId -replace "\b[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}\b", (New-Guid) } $json | ConvertTo-Json -Depth 100 | Set-Content -Path $Path } else { Write-Host -ForegroundColor Yellow "The file in $Path was not found." } } |