# Create DOS directory and push system files
$password = ConvertTo-SecureString "Paper123!@#" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential("INTRANET\sysadmin", $password)

Write-Host "=== Fixing DOS System Files ===" -ForegroundColor Cyan
Write-Host ""

Invoke-Command -ComputerName 192.168.0.6 -Credential $cred -ScriptBlock {
    param($autoexecContent, $startnetContent)

    Write-Host "[1] Checking directory structure" -ForegroundColor Yellow

    # Check if COMMON\DOS exists, create if not
    $dosDir = "C:\Shares\test\COMMON\DOS"

    if (-not (Test-Path $dosDir)) {
        Write-Host "[INFO] Creating directory: $dosDir" -ForegroundColor Cyan
        New-Item -Path $dosDir -ItemType Directory -Force | Out-Null
        Write-Host "[OK] Directory created" -ForegroundColor Green
    } else {
        Write-Host "[OK] Directory exists: $dosDir" -ForegroundColor Green
    }

    Write-Host ""
    Write-Host "[2] Copying AUTOEXEC.BAT" -ForegroundColor Yellow
    $autoexecPath = Join-Path $dosDir "AUTOEXEC.BAT"
    $autoexecContent | Out-File -FilePath $autoexecPath -Encoding ASCII -Force
    Write-Host "[OK] Copied to: $autoexecPath" -ForegroundColor Green

    Write-Host ""
    Write-Host "[3] Copying STARTNET.BAT" -ForegroundColor Yellow
    $startnetPath = Join-Path $dosDir "STARTNET.BAT"
    $startnetContent | Out-File -FilePath $startnetPath -Encoding ASCII -Force
    Write-Host "[OK] Copied to: $startnetPath" -ForegroundColor Green

    Write-Host ""
    Write-Host "[4] Listing files in COMMON\DOS" -ForegroundColor Yellow
    Get-ChildItem $dosDir | ForEach-Object {
        Write-Host "  $($_.Name)" -ForegroundColor Gray
    }

} -ArgumentList (Get-Content "D:\ClaudeTools\AUTOEXEC.BAT" -Raw), (Get-Content "D:\ClaudeTools\STARTNET.BAT" -Raw)

Write-Host ""
Write-Host "=== Complete ===" -ForegroundColor Cyan
Write-Host "[INFO] All 10 fixed BAT files now on AD2" -ForegroundColor Green
Write-Host "[INFO] Next sync will push to NAS (/data/test/)" -ForegroundColor Cyan
Write-Host "[INFO] DOS machines can access at T:\ drive" -ForegroundColor Cyan
