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

@ -1,6 +1,6 @@
Script,Description SCRIPT,DESCRIPTION
add-firewall-rules.ps1, Adds firewall rules to the given executables (needs admin rights) add-firewall-rules.ps1, Adds firewall rules for executables (needs admin rights)
add-memo.ps1, Adds the given memo text to $HOME/Memos.csv add-memo.ps1, Adds a memo text
build-repo.ps1, Builds a Git repository build-repo.ps1, Builds a Git repository
build-repos.ps1, Builds all Git repositories in a folder build-repos.ps1, Builds all Git repositories in a folder
cd-autostart.ps1, Set the working directory to the user's autostart folder cd-autostart.ps1, Set the working directory to the user's autostart folder

1 Script SCRIPT Description DESCRIPTION
2 add-firewall-rules.ps1 Adds firewall rules to the given executables (needs admin rights) Adds firewall rules for executables (needs admin rights)
3 add-memo.ps1 Adds the given memo text to $HOME/Memos.csv Adds a memo text
4 build-repo.ps1 Builds a Git repository Builds a Git repository
5 build-repos.ps1 Builds all Git repositories in a folder Builds all Git repositories in a folder
6 cd-autostart.ps1 Set the working directory to the user's autostart folder Set the working directory to the user's autostart folder

View File

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

View File

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

View File

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