Comprehensive infrastructure improvements for AD2 (Domain Controller) remote management and NAS sync system modernization. ## AD2 Remote Access Enhancements **WinRM Configuration:** - Enabled PowerShell Remoting (port 5985) with full logging - Configured TrustedHosts for LAN/VPN access (172.16.*, 192.168.*, 10.*) - Created read-only service account (ClaudeTools-ReadOnly) for safe automation - Set up transcript logging for all remote sessions - Deployed 6 automation scripts to C:\ClaudeTools\Scripts\ (AD user/computer reports, GPO status, replication health, log rotation) **SSH Access:** - Installed OpenSSH Server (v10.0p2) - Generated ED25519 key for passwordless authentication - Configured SSH key authentication for sysadmin account **Benefits:** - Efficient remote operations via persistent WinRM sessions (vs individual SSH commands) - Secure read-only access for queries (no admin rights needed) - Comprehensive audit trail of all remote operations ## Sync System Modernization (AD2 <-> NAS) **Replaced PuTTY with OpenSSH:** - Migrated from pscp.exe/plink.exe to native OpenSSH scp/ssh tools - Added verbose logging (-v flag) for detailed error diagnostics - Implemented auto host-key acceptance (StrictHostKeyChecking=accept-new) - Enhanced error logging to capture actual SCP failure reasons **Problem Solved:** - Original sync errors (738 failures) had no root cause details - PuTTY's batch mode silently failed without error messages - New OpenSSH implementation logs full error output to sync-from-nas.log **Scripts Created:** - setup-openssh-sync.ps1: SSH key generation and NAS configuration - check-openssh-client.ps1: Verify OpenSSH availability - restore-and-fix-sync.ps1: Update Sync-FromNAS.ps1 to use OpenSSH - investigate-sync-errors.ps1: Analyze sync failures with context - test-winrm.ps1: WinRM connection testing (admin + service accounts) - demo-ad2-automation.ps1: WinRM automation examples (AD stats, sync status) ## DOS Batch File Line Ending Fixes **Problem:** All DOS batch files had Unix (LF) line endings instead of DOS (CRLF), causing parsing errors on DOS 6.22 machines. **Fixed:** - Local: 13 batch files converted to CRLF - Remote (AD2): 492 batch files scanned, 10 converted to CRLF - Affected files: DEPLOY.BAT, NWTOC.BAT, CTONW.BAT, UPDATE.BAT, STAGE.BAT, CHECKUPD.BAT, REBOOT.BAT, and station-specific batch files **Scripts Created:** - check-dos-line-endings.ps1: Scan and detect LF vs CRLF - convert-to-dos.ps1: Bulk conversion to DOS format - fix-ad2-dos-files.ps1: Remote conversion via WinRM ## Credentials & Documentation Updates **credentials.md additions:** - Peaceful Spirit VPN configuration (L2TP/IPSec) - AD2 WinRM/SSH access details (both admin and service accounts) - SSH keys and known_hosts configuration - Complete WinRM connection examples **Files Modified:** - credentials.md: +91 lines (VPN, AD2 automation access) - CTONW.BAT, NWTOC.BAT, REBOOT.BAT, STAGE.BAT: Line ending fixes - Infrastructure configs: vpn-connect.bat, vpn-disconnect.bat (CRLF) ## Test Results **WinRM Automation (demo-ad2-automation.ps1):** - Retrieved 178 AD users (156 enabled, 22 disabled, 40 active) - Retrieved 67 AD computers (67 Windows, 6 servers, 53 active) - Checked Dataforth sync status (2,249 files pushed, 738 errors logged) - All operations completed in single remote session (efficient!) **Sync System:** - OpenSSH tools confirmed available on AD2 - Backup created: Sync-FromNAS.ps1.backup-20260119-140918 - Script updated with error logging and verbose output - Next sync run will reveal actual error causes ## Technical Decisions 1. **WinRM over SSH:** More efficient for PowerShell operations, better error handling, native Windows integration 2. **Service Account:** Follows least-privilege principle, safer for automated queries, easier audit trail 3. **OpenSSH over PuTTY:** Modern, maintained, native Windows tool, better error reporting, supports key authentication without external tools 4. **Verbose Logging:** Critical for debugging 738 sync errors - now we'll see actual SCP failure reasons (permissions, paths, network issues) ## Next Steps 1. Monitor next sync run (every 15 minutes) for detailed error messages 2. Analyze SCP error output to identify root cause of 738 failures 3. Implement SSH key authentication for NAS (passwordless) 4. Consider SFTP batch mode for more reliable transfers Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
134 lines
5.8 KiB
PowerShell
134 lines
5.8 KiB
PowerShell
# Investigate Dataforth Sync Errors on AD2
|
|
Write-Host "=== Investigating Dataforth Sync Errors ===" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# Setup admin credentials for AD2
|
|
$password = ConvertTo-SecureString "Paper123!@#" -AsPlainText -Force
|
|
$cred = New-Object System.Management.Automation.PSCredential("INTRANET\sysadmin", $password)
|
|
|
|
Write-Host "Connecting to AD2 and analyzing sync logs..." -ForegroundColor Yellow
|
|
Write-Host ""
|
|
|
|
Invoke-Command -ComputerName 192.168.0.6 -Credential $cred -ScriptBlock {
|
|
$logFile = "C:\Shares\test\scripts\sync-from-nas.log"
|
|
$statusFile = "C:\Shares\test\_SYNC_STATUS.txt"
|
|
|
|
Write-Host "[1] Current Sync Status" -ForegroundColor Yellow
|
|
Write-Host "=" * 60 -ForegroundColor Gray
|
|
if (Test-Path $statusFile) {
|
|
Get-Content $statusFile
|
|
} else {
|
|
Write-Host "Status file not found" -ForegroundColor Red
|
|
}
|
|
Write-Host ""
|
|
|
|
Write-Host "[2] Log File Information" -ForegroundColor Yellow
|
|
Write-Host "=" * 60 -ForegroundColor Gray
|
|
if (Test-Path $logFile) {
|
|
$file = Get-Item $logFile
|
|
Write-Host "File: $($file.FullName)" -ForegroundColor White
|
|
Write-Host "Size: $([math]::Round($file.Length / 1MB, 2)) MB" -ForegroundColor White
|
|
Write-Host "Last Modified: $($file.LastWriteTime)" -ForegroundColor White
|
|
Write-Host "Lines: $((Get-Content $logFile).Count)" -ForegroundColor White
|
|
} else {
|
|
Write-Host "Log file not found: $logFile" -ForegroundColor Red
|
|
return
|
|
}
|
|
Write-Host ""
|
|
|
|
Write-Host "[3] Analyzing Errors (last 1000 lines)" -ForegroundColor Yellow
|
|
Write-Host "=" * 60 -ForegroundColor Gray
|
|
|
|
# Read last 1000 lines to analyze recent errors
|
|
$recentLines = Get-Content $logFile -Tail 1000
|
|
|
|
# Count error types
|
|
$errors = $recentLines | Select-String -Pattern "ERROR|Error|error|FAIL|Failed|failed"
|
|
$warnings = $recentLines | Select-String -Pattern "WARNING|Warning|warning"
|
|
|
|
Write-Host "Total Error Lines (last 1000): $($errors.Count)" -ForegroundColor $(if ($errors.Count -gt 0) { "Red" } else { "Green" })
|
|
Write-Host "Total Warning Lines (last 1000): $($warnings.Count)" -ForegroundColor $(if ($warnings.Count -gt 0) { "Yellow" } else { "Green" })
|
|
Write-Host ""
|
|
|
|
if ($errors.Count -gt 0) {
|
|
Write-Host "[4] Error Breakdown" -ForegroundColor Yellow
|
|
Write-Host "=" * 60 -ForegroundColor Gray
|
|
|
|
# Analyze common error patterns
|
|
$errorPatterns = @{
|
|
"No such file" = "No such file|not found|cannot find"
|
|
"Permission denied" = "Permission denied|Access denied|Access is denied"
|
|
"Connection" = "Connection|connect|timeout"
|
|
"File in use" = "being used|in use|locked"
|
|
"SSH/SCP" = "ssh|scp|plink|pscp"
|
|
}
|
|
|
|
foreach ($pattern in $errorPatterns.Keys) {
|
|
$count = ($errors | Select-String -Pattern $errorPatterns[$pattern]).Count
|
|
if ($count -gt 0) {
|
|
Write-Host " $pattern`: $count" -ForegroundColor Red
|
|
}
|
|
}
|
|
Write-Host ""
|
|
|
|
Write-Host "[5] Sample Errors (last 15)" -ForegroundColor Yellow
|
|
Write-Host "=" * 60 -ForegroundColor Gray
|
|
$errors | Select-Object -Last 15 | ForEach-Object {
|
|
# Remove timestamp and show just the error
|
|
$line = $_.Line -replace '^\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\s+:\s+', ''
|
|
Write-Host " $line" -ForegroundColor Red
|
|
}
|
|
Write-Host ""
|
|
}
|
|
|
|
Write-Host "[6] Recent Sync Activity (last 10 operations)" -ForegroundColor Yellow
|
|
Write-Host "=" * 60 -ForegroundColor Gray
|
|
$recentLines | Select-String -Pattern "Pushed:|Pulled:|Deleted:" | Select-Object -Last 10 | ForEach-Object {
|
|
Write-Host " $($_.Line)" -ForegroundColor Gray
|
|
}
|
|
Write-Host ""
|
|
|
|
Write-Host "[7] Today's Summary" -ForegroundColor Yellow
|
|
Write-Host "=" * 60 -ForegroundColor Gray
|
|
$today = Get-Date -Format "yyyy-MM-dd"
|
|
$todayLines = $recentLines | Where-Object { $_ -like "*$today*" }
|
|
|
|
if ($todayLines) {
|
|
$todayPush = ($todayLines | Select-String -Pattern "Pushed:").Count
|
|
$todayPull = ($todayLines | Select-String -Pattern "Pulled:").Count
|
|
$todayDelete = ($todayLines | Select-String -Pattern "Deleted:").Count
|
|
$todayErrors = ($todayLines | Select-String -Pattern "ERROR|Error|error|FAIL").Count
|
|
|
|
Write-Host " Files Pushed: $todayPush" -ForegroundColor Green
|
|
Write-Host " Files Pulled: $todayPull" -ForegroundColor Green
|
|
Write-Host " Files Deleted: $todayDelete" -ForegroundColor Cyan
|
|
Write-Host " Errors: $todayErrors" -ForegroundColor $(if ($todayErrors -gt 0) { "Red" } else { "Green" })
|
|
} else {
|
|
Write-Host " No activity logged for today ($today)" -ForegroundColor Yellow
|
|
}
|
|
Write-Host ""
|
|
|
|
Write-Host "[8] Script Status" -ForegroundColor Yellow
|
|
Write-Host "=" * 60 -ForegroundColor Gray
|
|
$scriptPath = "C:\Shares\test\scripts\Sync-FromNAS.ps1"
|
|
if (Test-Path $scriptPath) {
|
|
$script = Get-Item $scriptPath
|
|
Write-Host " Script: $($script.Name)" -ForegroundColor White
|
|
Write-Host " Last Modified: $($script.LastWriteTime)" -ForegroundColor White
|
|
|
|
# Check if scheduled task exists
|
|
$task = Get-ScheduledTask -TaskName "Sync-FromNAS" -ErrorAction SilentlyContinue
|
|
if ($task) {
|
|
Write-Host " Scheduled Task: Enabled" -ForegroundColor Green
|
|
Write-Host " Task Status: $($task.State)" -ForegroundColor White
|
|
Write-Host " Last Run: $($task.LastRunTime)" -ForegroundColor White
|
|
Write-Host " Next Run: $($task.NextRunTime)" -ForegroundColor White
|
|
} else {
|
|
Write-Host " Scheduled Task: Not found" -ForegroundColor Red
|
|
}
|
|
}
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "=== Investigation Complete ===" -ForegroundColor Cyan
|