Skip to content

Instantly share code, notes, and snippets.

@biosmanager
Last active August 26, 2022 16:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biosmanager/7ad461508f80feb16f02d75619c35b95 to your computer and use it in GitHub Desktop.
Save biosmanager/7ad461508f80feb16f02d75619c35b95 to your computer and use it in GitHub Desktop.
Scheduled autostart using PowerShell. Programs only start within the specified time frame and not on your days off. Use task scheduler to run at logon. Repository at: https://github.com/biosmanager/scheduled-autostart
param (
$StartTime = '09:00',
$EndTime = '18:00',
$DaysOff = @('Saturday', 'Sunday')
)
$StartTimeDate = Get-Date $StartTime
$EndTimeDate = Get-Date $EndTime
$Date = Get-Date
if ($Date.DayOfWeek -notin $DaysOff -and (($Date.TimeOfDay -ge $StartTimeDate.TimeOfDay) -and ($Date.TimeOfDay -le $EndTimeDate.TimeOfDay))) {
# Autostart
Write-Output 'Another day, another dollar!'
Start-Process '<program1>' -RedirectStandardOutput nul
Start-Process '<program2>' -RedirectStandardOutput nul
}
else {
Write-Output 'Enjoy your freetime :)'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment