PowerShell/Scripts/add-memo.ps1

27 lines
687 B
PowerShell
Raw Normal View History

2020-12-29 15:14:21 +01:00
<#
2021-05-04 16:31:15 +02:00
.SYNTAX add-memo.ps1 [<text>]
.DESCRIPTION adds the given memo text to $HOME/Memos.csv
2021-03-22 20:10:18 +01:00
.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-05-04 16:31:15 +02:00
if (-not(test-path "$Path")) {
write-output "Time,User,Text" > "$Path"
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
}