Find based on txt list of terms

 avatar
user_8454105
plain_text
19 days ago
1.3 kB
1
Indexable
Never
# Define the path to the search terms file and the solution directory
$searchTermsFile = "path\to\search_terms.txt"
$solutionDirectory = "path\to\your\solution"

# Read the search terms into an array
$searchTerms = Get-Content $searchTermsFile

# Initialize an empty hashtable to store results
$results = @{}

# Loop through each search term
foreach ($term in $searchTerms) {
    # Use Select-String to search for the term in the solution directory
    $matches = Select-String -Path "$solutionDirectory\*" -Pattern $term -Recurse
    
    # If matches are found, store them in the hashtable
    if ($matches) {
        $results[$term] = $matches
    } else {
        $results[$term] = $null
    }
}

# Output the orphan terms (those not found in the project)
$orphanTerms = $results.GetEnumerator() | Where-Object { $_.Value -eq $null } | ForEach-Object { $_.Key }

# Print the orphan terms
if ($orphanTerms.Count -gt 0) {
    Write-Host "Orphan terms found:"
    $orphanTerms | ForEach-Object { Write-Host $_ }
} else {
    Write-Host "No orphan terms found. All terms are used in the project."
}

# Optionally, save the results to a file
$orphanTerms | Out-File "path\to\output\orphan_terms.txt"



CALL USING 
.\find_orphan_terms.ps1
Leave a Comment