# Set up target folder $targetDir = "C:\scripts" if (-not (Test-Path $targetDir)) { New-Item -Path $targetDir -ItemType Directory | Out-Null } # Always overwrite heartbeat.ps1 $source1 = Resolve-Path ".\scripts\heartbeat.ps1" $dest1 = "$targetDir\heartbeat.ps1" Copy-Item $source1 -Destination $dest1 -Force # Only copy config.json if it does not exist $source2 = Resolve-Path ".\scripts\config.json" $dest2 = "$targetDir\config.json" if (-not (Test-Path $dest2)) { Copy-Item $source2 -Destination $dest2 -Force } # Set up scheduled task to run on system startup $taskName = "KtvHeartbeat" $action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -File `"$targetDir\heartbeat.ps1`"" $trigger = New-ScheduledTaskTrigger -AtStartup $principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest Register-ScheduledTask -Action $action -Trigger $trigger -Principal $principal -TaskName $taskName -Force Write-Host "ok Installation Complete: The script has been deployed and will run at system startup." -ForegroundColor Green