mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-12-25 16:18:55 +01:00
2.6 KiB
2.6 KiB
Script: remember.ps1
This PowerShell script saves the given text to 'Remember.csv' in your home folder.
Parameters
PS> ./remember.ps1 [[-text1] <String>] [[-text2] <String>] [[-text3] <String>] [<CommonParameters>]
-text1 <String>
Specifies the text to memorize
Required? false
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-text2 <String>
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-text3 <String>
Required? false
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
Example
PS> ./remember.ps1 "Buy apples"
✔️ Saved to /home/Markus/Remember.csv in 0s.
Notes
Author: Markus Fleschutz | License: CC0
Related Links
https://github.com/fleschutz/PowerShell
Script Content
<#
.SYNOPSIS
Remembers a text
.DESCRIPTION
This PowerShell script saves the given text to 'Remember.csv' in your home folder.
.PARAMETER text1
Specifies the text to memorize
.EXAMPLE
PS> ./remember.ps1 "Buy apples"
✔️ Saved to /home/Markus/Remember.csv in 0s.
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$text1 = "", [string]$text2 = "", [string]$text3 = "")
try {
if ($text1 -eq "") { $text1 = Read-Host "Enter what needs to be remembered" }
$stopWatch = [system.diagnostics.stopwatch]::startNew()
[string]$timestampString = Get-Date -UFormat %s
$timestampString = $timestampString -replace ',','.'
[int64]$unixTimestamp = $timestampString
$path = "~/Remember.csv"
if (-not(Test-Path "$path" -pathType leaf)) {
Write-Output "TIMESTAMP,TEXT" > $path
}
Write-Output "$($unixTimestamp),$text1 $text2 $text3" >> $path
$path = Resolve-Path $path
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
"✔️ Saved to $path in $($elapsed)s."
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
(generated by convert-ps2md.ps1 using the comment-based help of remember.ps1 as of 08/15/2024 09:50:53)