16 lines
1.2 KiB
PowerShell
16 lines
1.2 KiB
PowerShell
$ErrorActionPreference='Stop'
|
|
$log='C:\Windows\Temp\tps-preseed.log'
|
|
# Pre-seed: data+attributes+timestamps only (ACLs re-applied fresh at cutover, avoids remote-privilege issues).
|
|
# /B backup mode reads open/locked files where possible; locked live QB .QBW skips fast (/R:1) and is recopied clean at cutover.
|
|
$rc = 'robocopy "C:\Share" "\\TPS-SVR\Share" /E /COPY:DAT /DCOPY:DAT /B /R:1 /W:2 /Z /XJ /MT:16 /NFL /NDL /NP /LOG:' + $log
|
|
$action = New-ScheduledTaskAction -Execute 'cmd.exe' -Argument ('/c ' + $rc)
|
|
$principal = New-ScheduledTaskPrincipal -UserId 'NT AUTHORITY\SYSTEM' -LogonType ServiceAccount -RunLevel Highest
|
|
$settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Hours 12) -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
|
|
$task = New-ScheduledTask -Action $action -Principal $principal -Settings $settings
|
|
Register-ScheduledTask -TaskName 'TPS-Preseed-Copy' -InputObject $task -Force | Out-Null
|
|
Start-ScheduledTask -TaskName 'TPS-Preseed-Copy'
|
|
Start-Sleep -Seconds 12
|
|
"Task state: $((Get-ScheduledTask -TaskName 'TPS-Preseed-Copy').State)"
|
|
"-- log head --"
|
|
if(Test-Path $log){ Get-Content $log -TotalCount 14 } else { "(log not created yet)" }
|