April 30, 2026
# Use current directory as root
$rootPath = $PWD
# Output file
$outputFile = Join-Path $rootPath "FilteredPowerCodes.csv"
# Clear output file if it exists
if (Test-Path $outputFile) {
Remove-Item $outputFile
}
# Find all folders named "TV"
$tvFolders = Get-ChildItem -Path $rootPath -Recurse -Directory | Where-Object {
$_.Name -eq "TV"
}
$results = @()
foreach ($folder in $tvFolders) {
$csvFiles = Get-ChildItem -Path $folder.FullName -Recurse -Filter *.csv
foreach ($file in $csvFiles) {
$lines = Get-Content $file.FullName
foreach ($line in $lines) {
$upperLine = $line.ToUpper()
if (
($upperLine -match "POWER") -and
($upperLine -notmatch "POWER OFF")
) {
$results += $line
}
}
}
}
# Write raw lines directly (no headers, no quotes)
$results | Set-Content -Path $outputFile
Write-Host "Done. Results saved to $outputFile"