Skip to content

Instantly share code, notes, and snippets.

@Broxzier
Created February 26, 2025 09:34
Show Gist options
  • Save Broxzier/c8fb20d46ce634b86d177edf21340dc8 to your computer and use it in GitHub Desktop.
Save Broxzier/c8fb20d46ce634b86d177edf21340dc8 to your computer and use it in GitHub Desktop.
PowerShell script that iterates over all .meta files in the given directory (defaults to the parent working directory) to scan for duplicate GUIDs.
param (
[Parameter(Position = 0)]
[string]$FolderPath = $pwd.Path
)
Write-Host "Scanning for duplicate GUIDs. Please wait..."
# Find all .meta files recursively within the specified folder
$metaFiles = Get-ChildItem -Path $FolderPath -Filter "*.meta" -Recurse
# Loop through each .meta file and extract the GUIDs into an array
$guids = @()
foreach ($file in $metaFiles) {
try {
$content = Get-Content -LiteralPath $file.FullName
foreach ($line in $content) {
if ($line -match "^guid: ([0-9a-fA-F]{32})$") {
$guids += $Matches[1]
}
}
}
catch {
Write-Warning "Error reading file: $($file.FullName): $($_.Exception.Message)"
}
}
# Group the GUIDs and count occurrences
$groupedGuids = $guids | Group-Object
# Output duplicate GUIDs
$foundDuplicates = $false
foreach ($group in $groupedGuids) {
if ($group.Count -gt 1) {
Write-Host "Duplicate GUID: $($group.Name) (Count: $($group.Count))" -ForegroundColor Red
$foundDuplicates = $true
}
}
# If there were none, output that instead!
if (-not $foundDuplicates) {
Write-Host "No duplicate GUIDs were found."
}
@Broxzier
Copy link
Author

Example output:

Scanning for duplicate GUIDs. Please wait...
Duplicate GUID: cb3892a2411d7d74284ba952f374ca45 (Count: 2)

@Broxzier
Copy link
Author

Broxzier commented Feb 26, 2025

You can then use grep or similar tools to find the files or folders that have the duplicate GUIDs. For example, in a git repository you can run:

git grep --recurse-submodules cb3892a2411d7d74284ba952f374ca45 *.meta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment