# Find where the generic ERROR messages are logged $password = ConvertTo-SecureString "Paper123!@#" -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential("INTRANET\sysadmin", $password) Invoke-Command -ComputerName 192.168.0.6 -Credential $cred -ScriptBlock { $scriptPath = "C:\Shares\test\scripts\Sync-FromNAS.ps1" $content = Get-Content $scriptPath Write-Host "=== Finding ERROR Log Statements ===" -ForegroundColor Cyan Write-Host "" for ($i = 0; $i -lt $content.Count; $i++) { if ($content[$i] -match 'Write-Log.*ERROR.*Failed to (push|pull)') { Write-Host "Line $($i+1): $($content[$i])" -ForegroundColor Red # Show context (3 lines before and after) Write-Host "" Write-Host "Context:" -ForegroundColor Yellow for ($j = [math]::Max(0, $i-3); $j -le [math]::Min($content.Count-1, $i+3); $j++) { if ($j -eq $i) { Write-Host ">>> $($j+1): $($content[$j])" -ForegroundColor Red } else { Write-Host " $($j+1): $($content[$j])" -ForegroundColor Gray } } Write-Host "" } } }