diff --git a/README.md b/README.md index 6f330d1..1ed3080 100644 --- a/README.md +++ b/README.md @@ -1 +1,19 @@ -# ScheduledReboot \ No newline at end of file +# ScheduledReboot + +## What is it ? + +This script enables you to schedule a restart of a PC or a server at a wanted time. + +## How it works ? + +When the script is launched, it asks you to set the day of reboot (0 for today, 1 for tomorrow, 2 for after-tomorrow, etc...). +It asks you to set the hour too. +Default : today at 4 AM. +The time must be formatted as a decimal number (2 for 2:00 ; 14,5 for 14:30). + +## How to use it ? + +2 ways are available : the ps1 (powershell file), or the executable file. +Both are doing the same, but the display is different. + +Feel free to contact me at contact@alexandremottier.fr if you have any question. diff --git a/ScheduledReboot.exe b/ScheduledReboot.exe new file mode 100644 index 0000000..f10909a Binary files /dev/null and b/ScheduledReboot.exe differ diff --git a/ScheduledReboot.ps1 b/ScheduledReboot.ps1 new file mode 100644 index 0000000..531a629 --- /dev/null +++ b/ScheduledReboot.ps1 @@ -0,0 +1,19 @@ +# Déclaration des variables +$Date = Read-Host -Prompt "A quelle date doit redémarrer le serveur ? (aujourd'hui : 0 ; demain : 1)" +$Time = Read-Host -Prompt "A quelle heure doit redémarrer le serveur ? (defaut : 4h)" + +# Affectation de la valeur par défaut (si non complétion) +if (!$Date) +{ + $Date = 0 +} +if (!$Time) +{ + $Time = 4 +} + +# Envoi de la commande de shutdown basé sur l'heure saisie +shutdown -r -t ([decimal]::round(((Get-Date).AddDays($Date).Date.AddHours($Time) - (Get-Date)).TotalSeconds)) + +# Message affichant la bonne prise en compte de la demande +Write-Host "Le redémarrage du serveur a bien été programmé pour $Time h !" \ No newline at end of file