Files
powershell/accesspoint_compare.ps1
2023-03-09 09:06:25 +01:00

29 lines
1.2 KiB
PowerShell

# Set the paths to the files you want to compare
$file1 = "C:\ew-nagios\prod\etc\nagios\local\hostgroup-accesspoints.cfg"
$file2 = "C:\Users\a.warme\Documents\nps_cleanup\apworkfile2.txt"
# Read the contents of the files
$content1 = Get-Content $file1 -Raw
$content2 = Get-Content $file2 -Raw
# Split the file contents into words and remove any empty words
$words1 = $content1 -split "\W+" | Where-Object { $_ -ne "" }
$words2 = $content2 -split "\W+" | Where-Object { $_ -ne "" }
# Find matching words between the two files
$matchedWords = $words1 | Select-String -Pattern $words2 -SimpleMatch | ForEach-Object { $_.Line } | Get-Unique
# Get the line numbers of the matched lines in file 1
$matchedLineNumbers = $content1 | Select-String -Pattern $matchedWords | ForEach-Object { $_.LineNumber - 1 } | Get-Unique
# Open Notepad++ on the matched lines
if ($matchedLineNumbers) {
$lineNumbersString = $matchedLineNumbers -join ","
$command = "notepad++ $file1 -n$lineNumbersString"
Start-Process powershell -ArgumentList "-Command $command"
Write-Host "Notepad++ opened on the matched lines in nagios"
} else {
Write-Host "No matching lines found in nagios"
}