PowerShell/Scripts/add-memo.ps1

38 lines
885 B
PowerShell
Raw Normal View History

2021-09-27 10:38:12 +02:00
<#
2021-07-13 19:03:30 +02:00
.SYNOPSIS
2021-10-12 21:51:51 +02:00
Adds a memo text to $HOME/Memos.csv
2021-07-13 19:03:30 +02:00
.DESCRIPTION
2021-10-12 21:51:51 +02:00
This script adds the given memo text to $HOME/Memos.csv.
.PARAMETER text
Specifies the text to memorize
2021-07-13 19:03:30 +02:00
.EXAMPLE
2021-09-24 08:57:08 +02:00
PS> ./add-memo "Buy apples"
2021-10-04 17:42:06 +02:00
added to 📄/home/markus/Memos.csv
2021-07-13 19:03:30 +02:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
2021-08-29 17:50:03 +02:00
Author: Markus Fleschutz · License: CC0
2020-12-29 15:14:21 +01:00
#>
2020-12-24 10:29:13 +01:00
2021-08-24 20:46:03 +02:00
param([string]$text = "")
2020-12-24 10:29:13 +01:00
try {
2021-08-24 20:46:03 +02:00
if ($text -eq "" ) { $text = read-host "Enter the memo text to add" }
2021-05-04 16:31:15 +02:00
$Path = "$HOME/Memos.csv"
2020-12-29 15:14:21 +01:00
$Time = get-date -format "yyyy-MM-ddTHH:mm:ssZ" -asUTC
2020-12-25 11:57:09 +01:00
$User = $(whoami)
2021-08-24 20:46:03 +02:00
$Line = "$Time,$User,$text"
2020-12-24 10:29:13 +01:00
2021-06-07 08:48:17 +02:00
if (-not(test-path "$Path" -pathType leaf)) {
2021-08-24 20:46:03 +02:00
write-output "Time,User,text" > "$Path"
2021-05-04 16:41:47 +02:00
}
2021-05-04 16:31:15 +02:00
write-output $Line >> "$Path"
"✔️ added to 📄$Path"
2021-09-27 10:09:45 +02:00
exit 0 # success
2020-12-24 10:29:13 +01:00
} catch {
2021-09-16 20:19:10 +02:00
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
2020-12-24 10:29:13 +01:00
exit 1
}