$password = ConvertTo-SecureString 'Paper123!@#' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential('INTRANET\sysadmin', $password)

Write-Host "================================================" -ForegroundColor Cyan
Write-Host "Deploying Correct BAT Files to AD2" -ForegroundColor Cyan
Write-Host "================================================" -ForegroundColor Cyan
Write-Host ""

# Map network drive
Write-Host "[1/4] Mapping network drive to AD2..." -ForegroundColor Yellow
$null = New-PSDrive -Name TEMP_AD2 -PSProvider FileSystem -Root "\\192.168.0.6\C$" -Credential $cred -ErrorAction Stop
Write-Host "[OK] Network drive mapped" -ForegroundColor Green
Write-Host ""

# Copy to _COMMON\ProdSW (update old versions)
Write-Host "[2/4] Updating _COMMON\ProdSW with correct versions..." -ForegroundColor Yellow
Copy-Item D:\ClaudeTools\DEPLOY.BAT "TEMP_AD2:\Shares\test\_COMMON\ProdSW\" -Force
Copy-Item D:\ClaudeTools\CTONW.BAT "TEMP_AD2:\Shares\test\_COMMON\ProdSW\" -Force
Copy-Item D:\ClaudeTools\CTONWTXT.BAT "TEMP_AD2:\Shares\test\_COMMON\ProdSW\" -Force
Copy-Item D:\ClaudeTools\NWTOC.BAT "TEMP_AD2:\Shares\test\_COMMON\ProdSW\" -Force
Copy-Item D:\ClaudeTools\UPDATE.BAT "TEMP_AD2:\Shares\test\_COMMON\ProdSW\" -Force
Copy-Item D:\ClaudeTools\CHECKUPD.BAT "TEMP_AD2:\Shares\test\_COMMON\ProdSW\" -Force
Copy-Item D:\ClaudeTools\STAGE.BAT "TEMP_AD2:\Shares\test\_COMMON\ProdSW\" -Force
Copy-Item D:\ClaudeTools\REBOOT.BAT "TEMP_AD2:\Shares\test\_COMMON\ProdSW\" -Force
Write-Host "[OK] _COMMON\ProdSW updated" -ForegroundColor Green
Write-Host ""

# Copy to COMMON\ProdSW (ensure latest)
Write-Host "[3/4] Ensuring COMMON\ProdSW has latest versions..." -ForegroundColor Yellow
Copy-Item D:\ClaudeTools\DEPLOY.BAT "TEMP_AD2:\Shares\test\COMMON\ProdSW\" -Force
Copy-Item D:\ClaudeTools\CTONW.BAT "TEMP_AD2:\Shares\test\COMMON\ProdSW\" -Force
Copy-Item D:\ClaudeTools\CTONWTXT.BAT "TEMP_AD2:\Shares\test\COMMON\ProdSW\" -Force
Copy-Item D:\ClaudeTools\NWTOC.BAT "TEMP_AD2:\Shares\test\COMMON\ProdSW\" -Force
Copy-Item D:\ClaudeTools\UPDATE.BAT "TEMP_AD2:\Shares\test\COMMON\ProdSW\" -Force
Copy-Item D:\ClaudeTools\CHECKUPD.BAT "TEMP_AD2:\Shares\test\COMMON\ProdSW\" -Force
Copy-Item D:\ClaudeTools\STAGE.BAT "TEMP_AD2:\Shares\test\COMMON\ProdSW\" -Force
Copy-Item D:\ClaudeTools\REBOOT.BAT "TEMP_AD2:\Shares\test\COMMON\ProdSW\" -Force
Write-Host "[OK] COMMON\ProdSW updated" -ForegroundColor Green
Write-Host ""

# Copy DEPLOY.BAT to root
Write-Host "[4/4] Copying DEPLOY.BAT to root (C:\Shares\test\)..." -ForegroundColor Yellow
Copy-Item D:\ClaudeTools\DEPLOY.BAT "TEMP_AD2:\Shares\test\" -Force
Write-Host "[OK] DEPLOY.BAT copied to root" -ForegroundColor Green
Write-Host ""

# Cleanup
Remove-PSDrive -Name TEMP_AD2

Write-Host "================================================" -ForegroundColor Green
Write-Host "Deployment Complete!" -ForegroundColor Green
Write-Host "================================================" -ForegroundColor Green
Write-Host ""
Write-Host "Files deployed to:" -ForegroundColor Cyan
Write-Host "  - C:\Shares\test\COMMON\ProdSW\" -ForegroundColor White
Write-Host "  - C:\Shares\test\_COMMON\ProdSW\" -ForegroundColor White
Write-Host "  - C:\Shares\test\DEPLOY.BAT (root)" -ForegroundColor White
Write-Host ""
