Add remind-me.ps1

This commit is contained in:
Markus Fleschutz 2021-10-04 13:31:02 +02:00
parent 67a273f06e
commit 5a044708c5
3 changed files with 38 additions and 5 deletions

View File

@ -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

View File

@ -2,9 +2,10 @@
.SYNOPSIS
new-script.ps1 [<filename>]
.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))"

31
Scripts/remind-me.ps1 Executable file
View File

@ -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
}