Skip to content
EliteGo IT

Projects & Field Notes

  • Co-managed IT
  • Hybrid infrastructure

A daily PowerShell task that runs itself at 7:00 every morning

A recurring server task was being run by hand and missed whenever staff were away. We automated it to run every morning, unattended.

Client
Business client (name withheld)
Task Scheduler trigger settings: schedule type, start time and recurrence

The problem

A customer had a job that needed to run every morning on a Windows Server. Staff were running it by hand, so it was missed whenever they were away and ran at a different time each day. That led to follow-up support requests and made a routine task unreliable.

What we found

  • The task depended on a person remembering to run it
  • Run times varied, so anything relying on its output was inconsistent
  • Missed runs were turning into avoidable support tickets

What we did

  1. Wrote a PowerShell script to carry out the task and log the outcome of every run
  2. Scheduled it in Windows Task Scheduler to run daily at 7:00 AM
  3. Set it to run under a dedicated service account, whether or not anyone is logged in, with the rights the task needs
  4. Confirmed it ran on schedule and checked the log after the first runs
Windows Task Scheduler Create Basic Task wizard
Creating the task in Windows Task Scheduler

The script and task registration, with customer-specific details removed:

# daily-task.ps1 (sanitised: customer-specific steps removed)
$log = 'C:\Logs\DailyAutomation.log'
try {
    # ... customer-specific task runs here ...
    Add-Content -Path $log -Value "$(Get-Date -Format s) Completed"
}
catch {
    Add-Content -Path $log -Value "$(Get-Date -Format s) FAILED: $($_.Exception.Message)"
    exit 1
}
# Register the task: daily at 07:00, dedicated service account,
# runs whether or not anyone is logged in
$cred = Get-Credential 'DOMAIN\svc-dailytask'
$task = @{
    TaskName = 'Daily Automation'
    Action   = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -File "C:\Scripts\daily-task.ps1"'
    Trigger  = New-ScheduledTaskTrigger -Daily -At 7:00am
    User     = $cred.UserName
    Password = $cred.GetNetworkCredential().Password
    RunLevel = 'Highest'
}
Register-ScheduledTask @task
PowerShell registering a scheduled task and confirming it is ready
Registering the task with PowerShell

The result

The task now runs every morning without anyone touching it. Missed runs have stopped, and no further support requests have been needed for it since it went live.

What to take from it

If a task happens on a schedule, it shouldn’t depend on someone remembering it. A logged, scheduled script running under its own service account is quick to build and removes a steady source of errors and tickets. This is the kind of work we pick up alongside a client’s existing IT provider.