How to Schedule an Automatic Restart of Gespage Services on Windows

Summary: This article provides an all-in-one PowerShell script to easily create a scheduled task that automatically restarts all Gespage services. This is useful for preventive maintenance and ensuring maximum solution stability.

Keywords / Tags: Gespage, restart, schedule, scheduled task, PowerShell, maintenance, script, automatic


Article Content:

Objective

To ensure optimal performance and stability, it can be beneficial to periodically restart the Gespage services on your Windows server. This article guides you through automating this process using a single PowerShell script. The script will create a scheduled task for you that will run every day at 3:00 AM, requiring no further intervention.

Prerequisites

  • Access to the Windows server where Gespage is installed.

  • Administrator rights on this server to run the script and create the scheduled task.


Step-by-Step Procedure

Follow these three simple steps to set up the automatic restart.

Step 1: Prepare the Configuration Script

  1. Open Notepad on your server.

  2. Copy the entire code block below and paste it into Notepad.

PowerShell
# ===================================================================
# ALL-IN-ONE SCRIPT TO CONFIGURE GESPAGE SERVICES RESTART
# Run this script only once as an administrator.
# It will create a scheduled task to automate the restarts.
# ===================================================================

# --- Task Parameters ---
$TaskName = "Maintenance - Daily Restart of Gespage Services"
$TaskDescription = "Task that restarts Gespage services (gespagegf, gespage-mobile-gateway, etc.) every day at 3:00 AM."
$services = "'gespagegf','gespage-mobile-gateway','GEPS-Mobile','gespageprint','GespageUserInterface'"

# --- Command that will be executed daily by the task ---
$CommandToExecute = "Get-Service -Name $($services) | ForEach-Object { Restart-Service -InputObject $_ -Force }"

# --- Configure the task's action ---
$TaskAction = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-NoProfile -WindowStyle Hidden -Command `"$($CommandToExecute)`""

# --- Configure the task's trigger (daily at 3:00 AM) ---
$TaskTrigger = New-ScheduledTaskTrigger -Daily -At '3am'

# --- Configure the execution rights (SYSTEM Account) ---
$TaskPrincipal = New-ScheduledTaskPrincipal -UserId 'NT AUTHORITY\SYSTEM' -RunLevel Highest 
# --- Register the task in the Windows Task Scheduler ---
Write-Host "Creating scheduled task: '$TaskName'..."
try {    # The -Force option allows overwriting an existing task with the same name    Register-ScheduledTask -TaskName $TaskName -Action $TaskAction -Trigger $TaskTrigger -Principal $TaskPrincipal -Description $TaskDescription -Force -ErrorAction Stop    Write-Host "SUCCESS: The task has been created and configured." -ForegroundColor Green    Write-Host "Gespage services will now be restarted every day at 3:00 AM."
}
catch {    Write-Host "ERROR: Task creation failed." -ForegroundColor Red    Write-Host "Please ensure you are running this script as an administrator."    Write-Host "Error details: $($_.Exception.Message)"
} 
# Pause to allow the user to read the message
Write-Host "This window will close in 15 seconds..."
Start-Sleep -Seconds 15
  1. Save the file on your server's desktop. Give it a descriptive name, for example: Setup-GespageRestart.ps1.

Step 2: Run the Script

This is the action that will configure everything.

  1. Find the Setup-GespageRestart.ps1 file you just saved.

  2. Right-click on the file and, in the context menu, select "Run with PowerShell".

Note: If this option is not available, open the Start Menu, type "PowerShell", right-click on "Windows PowerShell" and choose "Run as administrator". Then, in the blue window, type the command cd $env:USERPROFILE\Desktop followed by .\Setup-GespageRestart.ps1 to run the script.

A script window will open, display a success message, and then close after a few seconds.

Step 3: Verify the Task Creation

To ensure that everything is set up correctly:

  1. Open the Task Scheduler by typing taskschd.msc in the Start Menu.

  2. In the "Task Scheduler Library", you should now see a new task named "Maintenance - Daily Restart of Gespage Services".

  3. This task is already active and configured. You don't need to do anything else. ✅


How to Customize the Restart Frequency

By default, the task is configured to run daily at 3:00 AM. You can easily change this schedule by following the steps below.

  1. Open the Task Scheduler (taskschd.msc).

  2. In the left pane, click on "Task Scheduler Library".

  3. Find the task "Maintenance - Daily Restart of Gespage Services" in the center list.

  4. Right-click on the task and choose "Properties".

  5. Go to the "Triggers" tab.

  6. Select the trigger from the list and click the "Edit..." button.

A new window will open, allowing you to reconfigure the schedule.

Example A: Run the Restart Once a Week

  • Under "Settings", select "Weekly".

  • Check the box for the day(s) you prefer (for example, only Sunday).

  • Verify the start time is correct, then click OK.

Example B: Run Every Two Days

  • Ensure "Daily" is selected.

  • Next to it, change the value for "Recur every: 1 days" to "2 days".

  • Click OK.

Example C: Run Multiple Times a Day

  • In the "Advanced settings" section of the trigger window, check the box for "Repeat task every:".

  • In the drop-down menu, choose the frequency (e.g., 1 hour or 4 hours).

  • For the duration, it is recommended to choose "1 day" so the cycle resets daily.

  • Click OK.

After modifying the trigger, click OK in the properties window to save your changes. The task will now run according to the new frequency you have defined.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article