# Verify BAT files are on the NAS
$password = ConvertTo-SecureString "Paper123!@#" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential("INTRANET\sysadmin", $password)

Write-Host "=== Checking BAT Files on NAS ===" -ForegroundColor Cyan
Write-Host ""

Invoke-Command -ComputerName 192.168.0.6 -Credential $cred -ScriptBlock {
    $SSH = "C:\Program Files\OpenSSH\ssh.exe"
    $NAS_IP = "192.168.0.9"
    $NAS_USER = "admin"

    Write-Host "[1] Listing root BAT files on NAS" -ForegroundColor Yellow
    Write-Host "=" * 80 -ForegroundColor Gray

    $result = & $SSH -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile="C:\Shares\test\scripts\.ssh\known_hosts" "${NAS_USER}@${NAS_IP}" "ls -lh /volume1/test/*.BAT 2>/dev/null" 2>&1

    if ($LASTEXITCODE -eq 0) {
        $result | ForEach-Object { Write-Host "  $_" -ForegroundColor Gray }
    } else {
        Write-Host "[INFO] No BAT files found or connection issue" -ForegroundColor Yellow
    }

    Write-Host ""
    Write-Host "[2] Listing COMMON/DOS files on NAS" -ForegroundColor Yellow
    Write-Host "=" * 80 -ForegroundColor Gray

    $result = & $SSH -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile="C:\Shares\test\scripts\.ssh\known_hosts" "${NAS_USER}@${NAS_IP}" "ls -lh /volume1/test/COMMON/DOS/*.BAT 2>/dev/null" 2>&1

    if ($LASTEXITCODE -eq 0) {
        $result | ForEach-Object { Write-Host "  $_" -ForegroundColor Gray }
    } else {
        Write-Host "[INFO] No files in COMMON/DOS or directory doesn't exist" -ForegroundColor Yellow
    }
}

Write-Host ""
Write-Host "=== Check Complete ===" -ForegroundColor Cyan
