$password = ConvertTo-SecureString 'Paper123!@#' -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential('INTRANET\sysadmin', $password) Write-Host "Creating Sync Task via XML..." -ForegroundColor Cyan Invoke-Command -ComputerName 192.168.0.6 -Credential $cred -ScriptBlock { # Create task XML $taskXml = @' Sync test data and software updates between NAS and AD2 PT15M false 2026-01-20T10:00:00 true INTRANET\sysadmin Password HighestAvailable IgnoreNew false false true true false true true PT30M powershell.exe -ExecutionPolicy Bypass -NonInteractive -File "C:\Shares\test\scripts\Sync-FromNAS.ps1" C:\Shares\test\scripts '@ # Save XML to file $xmlPath = "C:\Temp\sync-task.xml" $taskXml | Out-File -FilePath $xmlPath -Encoding Unicode -Force Write-Host "[1] Deleting old task if exists..." -ForegroundColor Yellow schtasks /Delete /TN "Sync-FromNAS" /F 2>$null Write-Host "[2] Creating task from XML..." -ForegroundColor Yellow $result = schtasks /Create /XML $xmlPath /TN "Sync-FromNAS" /RU "INTRANET\sysadmin" /RP "Paper123!@#" /F Write-Host " $result" -ForegroundColor White Write-Host "" Write-Host "[3] Starting task..." -ForegroundColor Yellow schtasks /Run /TN "Sync-FromNAS" Write-Host "" Write-Host " Waiting 30 seconds for sync..." -ForegroundColor White Start-Sleep -Seconds 30 Write-Host "" Write-Host "[4] Checking task status..." -ForegroundColor Yellow schtasks /Query /TN "Sync-FromNAS" /FO LIST /V Write-Host "" Write-Host "[5] Last 25 lines of sync log..." -ForegroundColor Yellow if (Test-Path "C:\Shares\test\scripts\sync-from-nas.log") { Get-Content "C:\Shares\test\scripts\sync-from-nas.log" | Select-Object -Last 25 | ForEach-Object { Write-Host " $_" -ForegroundColor Gray } } }