PowerShell/Scripts/add-memo.ps1

37 lines
823 B
PowerShell
Raw Normal View History

2021-09-27 10:38:12 +02:00
<#
2021-07-13 19:03:30 +02:00
.SYNOPSIS
2022-01-29 12:47:46 +01:00
Adds a memo text
2021-07-13 19:03:30 +02:00
.DESCRIPTION
This PowerShell script saves the given memo text to Memos.csv in your home folder.
2021-10-12 21:51:51 +02:00
.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"
saved to 📄/home/markus/Memos.csv
2021-07-13 19:03:30 +02:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
2022-09-06 21:42:04 +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 {
if ($text -eq "" ) { $text = Read-Host "Enter the text to memorize" }
2021-08-24 20:46:03 +02:00
$Path = "~/Memos.csv"
$Time = Get-Date -format FileDateTimeUniversal
$Line = "$Time,$text"
2020-12-24 10:29:13 +01:00
if (-not(Test-Path "$Path" -pathType leaf)) {
Write-Output "TIME,TEXT" > "$Path"
2021-05-04 16:41:47 +02:00
}
Write-Output $Line >> "$Path"
2021-05-04 16:31:15 +02:00
"✔️ saved to 📄$Path"
2021-09-27 10:09:45 +02:00
exit 0 # success
2020-12-24 10:29:13 +01:00
} catch {
2022-04-13 12:06:32 +02:00
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2020-12-24 10:29:13 +01:00
exit 1
}