From 5a044708c59315d361436da5da74de9687783347 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Mon, 4 Oct 2021 13:31:02 +0200 Subject: [PATCH] Add remind-me.ps1 --- Data/template.ps1 | 5 +++-- Scripts/new-script.ps1 | 7 ++++--- Scripts/remind-me.ps1 | 31 +++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 5 deletions(-) create mode 100755 Scripts/remind-me.ps1 diff --git a/Data/template.ps1 b/Data/template.ps1 index 57621dbd..79679253 100755 --- a/Data/template.ps1 +++ b/Data/template.ps1 @@ -1,5 +1,4 @@ -#requires -version 4 -<# +<# .SYNOPSIS ← enter overview of script here .DESCRIPTION @@ -17,6 +16,8 @@ ← enter URL here #> +#requires -version 4 + param() # ← enter script parameters here # ← enter functions here diff --git a/Scripts/new-script.ps1 b/Scripts/new-script.ps1 index 2cb11654..a8afdeda 100755 --- a/Scripts/new-script.ps1 +++ b/Scripts/new-script.ps1 @@ -2,9 +2,10 @@ .SYNOPSIS new-script.ps1 [] .DESCRIPTION - Creates a new PowerShell script + Creates a new PowerShell script file (by using template file ../Data/template.ps1). .EXAMPLE PS> ./new-script myscript.ps1 + ✔️ created new PowerShell script: myscript.ps1 .NOTES Author: Markus Fleschutz · License: CC0 .LINK @@ -16,9 +17,9 @@ param([string]$filename = "") try { if ($filename -eq "" ) { $shortcut = read-host "Enter the new filename" } - copy-item "$PSScriptRoot/../data/template.ps1" "$filename" + copy-item "$PSScriptRoot/../Data/template.ps1" "$filename" - "✔️ created new PowerShell script $filename" + "✔️ created new PowerShell script: $filename" exit 0 # success } catch { "⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))" diff --git a/Scripts/remind-me.ps1 b/Scripts/remind-me.ps1 new file mode 100755 index 00000000..b6490bd0 --- /dev/null +++ b/Scripts/remind-me.ps1 @@ -0,0 +1,31 @@ +<# +.SYNOPSIS + remind-me.ps1 +.DESCRIPTION + Creates a scheduled task that will display a message. +.EXAMPLE + PS> ./remind-me "Dentist" "1/1/2016 12:00 PM" + ✔ OK +.NOTES + Author: Markus Fleschutz · License: CC0 +.LINK + https://github.com/fleschutz/PowerShell +#> + +#requires -version 4 + +param([string]$Message = "", [datetime]$Time) + +try { + if ($Message -eq "") { $Message = read-host "Enter message to display" } + + $Task = New-ScheduledTaskAction -Execute msg -Argument "* $Message" + $Trigger = New-ScheduledTaskTrigger -Once -At $Time + $Random = (Get-Random) + Register-ScheduledTask -Action $Task -Trigger $Trigger -TaskName "Reminder_$Random" -Description "Reminder" + "✔️ OK" + exit 0 +} catch { + write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + exit 1 +}