Update add-memo.ps1, list-memos.ps1, and list-scripts.ps1

This commit is contained in:
Markus Fleschutz
2023-04-25 14:17:42 +02:00
parent 60c2008daa
commit bf81138941
4 changed files with 31 additions and 34 deletions

View File

@ -2,12 +2,12 @@
.SYNOPSIS
Adds a memo text
.DESCRIPTION
This PowerShell script adds the given memo text to $HOME/Memos.csv.
This PowerShell script saves the given memo text to Memos.csv in your home folder.
.PARAMETER text
Specifies the text to memorize
.EXAMPLE
PS> ./add-memo "Buy apples"
✔️ added to 📄/home/markus/Memos.csv
✔️ saved to 📄/home/markus/Memos.csv
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -17,19 +17,18 @@
param([string]$text = "")
try {
if ($text -eq "" ) { $text = read-host "Enter the memo text to add" }
if ($text -eq "" ) { $text = Read-Host "Enter the text to memorize" }
$Path = "$HOME/Memos.csv"
$Time = get-date -format "yyyy-MM-ddTHH:mm:ssZ" -asUTC
$User = $(whoami)
$Line = "$Time,$User,$text"
$Path = "~/Memos.csv"
$Time = Get-Date -format FileDateTimeUniversal
$Line = "$Time,$text"
if (-not(test-path "$Path" -pathType leaf)) {
write-output "Time,User,text" > "$Path"
if (-not(Test-Path "$Path" -pathType leaf)) {
Write-Output "TIME,TEXT" > "$Path"
}
write-output $Line >> "$Path"
Write-Output $Line >> "$Path"
"✔️ added to 📄$Path"
"✔️ saved to 📄$Path"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -1,8 +1,8 @@
<#
.SYNOPSIS
Lists all memos in $HOME/Memos.csv
Lists your memo entries
.DESCRIPTION
This PowerShell script lists all memo entries in Memos.csv in the home folder.
This PowerShell script lists all memo entries in Memos.csv in your home folder.
.EXAMPLE
PS> ./list-memos
.LINK
@ -13,20 +13,19 @@
try {
$Path = "$HOME/Memos.csv"
if (test-path "$Path" -pathType leaf) {
$Path = "~/Memos.csv"
if (Test-Path "$Path" -pathType leaf) {
write-progress "Reading $Path ..."
$Table = import-csv "$Path"
$Table = Import-CSV "$Path"
write-progress -completed "Reading $Path"
""
"Time User Text"
"---- ---- ----"
"Time Text"
"---- ----"
foreach($Row in $Table) {
$Time = $Row.Time
$User = $Row.User
$Text = $Row.Text
"$Time $User $Text"
"$Time $Text"
}
} else {
"Sorry, no memos saved yet"

View File

@ -1,6 +1,6 @@
<#
.SYNOPSIS
Lists all PowerShell scripts in this repository
Lists all PowerShell scripts
.DESCRIPTION
This PowerShell script lists all PowerShell scripts in the repository (sorted alphabetically).
.EXAMPLE
@ -12,23 +12,22 @@
#>
function ListScripts { param([string]$FilePath)
write-progress "Reading $FilePath..."
$Table = import-csv "$FilePath"
foreach($Row in $Table) {
Write-Progress "Reading $FilePath..."
$table = Import-CSV "$FilePath"
[int]$No = 1
foreach($row in $table) {
New-Object PSObject -Property @{
'PowerShell Script' = "$($Row.Script)"
'Description' = "$($Row.Description)"
'No' = $No++
'Script' = $row.SCRIPT
'Description' = $row.DESCRIPTION
}
}
$global:NumScripts = $Table.Count
write-progress -completed "Reading $FilePath..."
Write-Progress -completed "."
}
try {
$PathToRepo = "$PSScriptRoot/.."
ListScripts "$PathToRepo/Data/scripts.csv" | format-table -property "PowerShell Script",Description
"✔️ $($global:NumScripts) PowerShell scripts total"
ListScripts "$PSScriptRoot/../Data/scripts.csv" | Format-Table -property No,Script,Description
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"