# Check DEPLOY.BAT and UPDATE.BAT on AD2

$Username = "INTRANET\sysadmin"
$Password = ConvertTo-SecureString "Paper123!@#" -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential($Username, $Password)

Write-Host "[INFO] Connecting to AD2..."

New-PSDrive -Name TEMP_AD2 -PSProvider FileSystem -Root "\\192.168.0.6\C$" -Credential $Cred -ErrorAction Stop | Out-Null

Write-Host "[INFO] Checking DEPLOY.BAT and UPDATE.BAT..."
Write-Host ""

$DeployFile = Get-Item "TEMP_AD2:\Shares\test\DEPLOY.BAT" -ErrorAction SilentlyContinue
$UpdateFile = Get-Item "TEMP_AD2:\Shares\test\UPDATE.BAT" -ErrorAction SilentlyContinue

if ($DeployFile) {
    Write-Host "[OK] DEPLOY.BAT found on AD2"
    Write-Host "    Last Modified: $($DeployFile.LastWriteTime)"
    Write-Host "    Size: $($DeployFile.Length) bytes"

    # Check line endings
    $Content = Get-Content "TEMP_AD2:\Shares\test\DEPLOY.BAT" -Raw
    if ($Content -match "`r`n") {
        Write-Host "    Line Endings: CRLF (DOS-compatible) [OK]"
    } elseif ($Content -match "`n") {
        Write-Host "    Line Endings: LF only [WARNING]"
    }
} else {
    Write-Host "[ERROR] DEPLOY.BAT not found on AD2"
}

Write-Host ""

if ($UpdateFile) {
    Write-Host "[OK] UPDATE.BAT found on AD2"
    Write-Host "    Last Modified: $($UpdateFile.LastWriteTime)"
    Write-Host "    Size: $($UpdateFile.Length) bytes"

    # Check line endings
    $Content = Get-Content "TEMP_AD2:\Shares\test\UPDATE.BAT" -Raw
    if ($Content -match "`r`n") {
        Write-Host "    Line Endings: CRLF (DOS-compatible) [OK]"
    } elseif ($Content -match "`n") {
        Write-Host "    Line Endings: LF only [WARNING]"
    }
} else {
    Write-Host "[ERROR] UPDATE.BAT not found on AD2"
}

Remove-PSDrive TEMP_AD2
Write-Host ""
Write-Host "[INFO] Note: Files sync to NAS every 15 minutes via AD2's scheduled task"
