# Copy UPDATE.BAT and DEPLOY.BAT to AD2 root for sync

$Source = "D:\ClaudeTools"
$Destination = "\\192.168.0.6\C$\Shares\test"
$Username = "INTRANET\sysadmin"
$Password = ConvertTo-SecureString "Paper123!@#" -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential($Username, $Password)

Write-Host "Connecting to AD2..."
New-PSDrive -Name TEMP_AD2 -PSProvider FileSystem -Root "\\192.168.0.6\C$" -Credential $Cred | Out-Null
Write-Host "[OK] Connected to AD2"
Write-Host ""

# Copy UPDATE.BAT and DEPLOY.BAT to root of test
Write-Host "Copying UPDATE.BAT to AD2 root..."
Copy-Item "$Source\UPDATE.BAT" "TEMP_AD2:\Shares\test\UPDATE.BAT" -Force
Write-Host "  [OK] UPDATE.BAT -> C:\Shares\test\UPDATE.BAT"

Write-Host "Copying DEPLOY.BAT to AD2 root..."
Copy-Item "$Source\DEPLOY.BAT" "TEMP_AD2:\Shares\test\DEPLOY.BAT" -Force
Write-Host "  [OK] DEPLOY.BAT -> C:\Shares\test\DEPLOY.BAT"

# Verify files exist
Write-Host ""
Write-Host "Verifying files on AD2:"
if (Test-Path "TEMP_AD2:\Shares\test\UPDATE.BAT") {
    $size = (Get-Item "TEMP_AD2:\Shares\test\UPDATE.BAT").Length
    Write-Host "  [OK] UPDATE.BAT exists ($size bytes)"
}
if (Test-Path "TEMP_AD2:\Shares\test\DEPLOY.BAT") {
    $size = (Get-Item "TEMP_AD2:\Shares\test\DEPLOY.BAT").Length
    Write-Host "  [OK] DEPLOY.BAT exists ($size bytes)"
}

# Show last sync status
Write-Host ""
Write-Host "=========================================="
Write-Host "Last Sync Status:"
Write-Host "=========================================="
Get-Content "TEMP_AD2:\Shares\test\_SYNC_STATUS.txt"

Write-Host ""
Write-Host "[INFO] Files are now in place for next sync (runs every 15 minutes)"
Write-Host "[INFO] Next sync will push UPDATE.BAT and DEPLOY.BAT to NAS root (T:\)"

Remove-PSDrive TEMP_AD2
