PowerShell/Scripts/add-memo.ps1

34 lines
731 B
PowerShell
Raw Normal View History

2020-12-29 15:14:21 +01:00
<#
2021-07-13 19:03:30 +02:00
.SYNOPSIS
add-memo.ps1 [<text>]
.DESCRIPTION
Adds the given memo text to $HOME/Memos.csv
.EXAMPLE
PS> .\add-memo.ps1 "Buy apples"
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz / License: CC0
2020-12-29 15:14:21 +01:00
#>
2020-12-24 10:29:13 +01:00
2021-02-18 20:17:55 +01:00
param($Text = "")
2021-05-04 16:31:15 +02:00
if ($Text -eq "" ) { $Text = read-host "Enter the memo text to add" }
2020-12-24 10:29:13 +01:00
try {
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)
$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-05-04 16:31:15 +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"
2020-12-24 10:29:13 +01:00
exit 0
} catch {
2021-05-02 21:30:48 +02:00
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2020-12-24 10:29:13 +01:00
exit 1
}