Improved the error message

This commit is contained in:
Markus Fleschutz 2020-12-09 09:30:55 +00:00
parent 30eccba205
commit f771cf7441
36 changed files with 152 additions and 77 deletions

View File

@ -15,5 +15,7 @@ try {
$Result = get-filehash $File -algorithm MD5
write-host "✔️ MD5 hash is" $Result.Hash
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -15,5 +15,7 @@ try {
$Result = get-filehash $File -algorithm SHA1
write-host "✔️ SHA1 hash is" $Result.Hash
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -15,5 +15,7 @@ try {
$Result = get-filehash $File -algorithm SHA256
write-host "✔️ SHA256 hash is" $Result.Hash
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -17,5 +17,7 @@ try {
curl --header "Access-Token: o.PZl5XCp6SBl4F5PpaNXGDfFpUJZKAlEb" --header "Content-Type: application/json" --data-binary '{"type": "note", "title": "ALERT", "body": "$Message"}' --request POST https://api.pushbullet.com/v2/pushes
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -8,12 +8,17 @@
$Repos = "https://github.com/commonmark/cmark", "https://github.com/opencv/opencv", "https://github.com/openzfs/zfs", "https://github.com/synesthesiam/voice2json", "https://github.com/fleschutz/CWTS", "https://github.com/fleschutz/cubesum", "https://github.com/fleschutz/PowerShell","https://github.com/fleschutz/CWTS", "https://github.com/fleschutz/eventdriven"
foreach ($Repo in $Repos) {
try {
foreach ($Repo in $Repos) {
$Answer = read-host "Do you want to clone $Repo (y/n)"
if ($Answer -eq "y") {
git clone $Repo
}
}
}
write-host "Done."
exit 0
write-host "Done."
exit 0
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -18,5 +18,7 @@ try {
git config --global init.defaultBranch main
echo "Done."
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -15,5 +15,7 @@ try {
wget --mirror --convert-links --adjust-extension --page-requisites --no-parent $URL --directory-prefix . --no-verbose
write-host "✔️ Done."
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -15,5 +15,7 @@ if ($File -eq "" ) {
try {
get-childitem $File | % {$_.VersionInfo} | Select *
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -32,5 +32,7 @@ try {
}
write-error "City $City not found"
exit 1
} catch { write-error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -9,5 +9,7 @@
try {
Get-Command -Command-Type cmdlet
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -14,5 +14,7 @@ try {
(Get-ChildItem $DirTree -recurse | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | select FullName
echo "Done."
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -9,5 +9,7 @@
try {
Get-Module
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -9,5 +9,7 @@
try {
Get-Process | Format-Table -Property Id, @{Label="CPU(s)";Expression={$_.CPU.ToString("N")+"%"};Alignment="Right"}, ProcessName -AutoSize
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -16,5 +16,7 @@ try {
Get-ChildItem -path $DirTree -recurse | Where-Object {$_.LastAccessTime -le $cutOffDate} | select fullname
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -20,5 +20,7 @@ try {
echo.
pause
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -9,5 +9,7 @@
try {
(Invoke-WebRequest http://wttr.in/Moon -UserAgent "curl" ).Content
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -21,5 +21,7 @@ try {
write-host "*" $item.title
}
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -23,5 +23,7 @@ try {
$password = new_password
write-output $password
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -26,5 +26,7 @@ try {
write-output $password
}
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -10,5 +10,7 @@
try {
Stop-Computer
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -10,5 +10,7 @@
try {
Restart-Computer
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -22,5 +22,7 @@ try {
$msg.body = $Body
$smtp.Send($msg)
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -28,5 +28,7 @@ try {
$Socket.Close()
echo "Done."
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -17,5 +17,7 @@ try {
$voice = New-Object ComObject SAPI.SPVoice
$voice.Speak($Text);
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -15,5 +15,7 @@ try {
$voice = New-Object ComObject SAPI.SPVoice
$voice.Speak($Text);
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -23,5 +23,7 @@ try {
write-host "OK - switched Shelly1 device at $IPaddr to $TurnMode for $Timer second(s)"
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -10,5 +10,7 @@ try {
write-output "✔️ PowerShell works. Details are:"
echo $PSVersionTable
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -21,5 +21,7 @@ try {
$TimeInterval = New-Timespan -start $StartTime -end $StopTime
write-host "OK - DNS cache trained with $Count domain names in $TimeInterval sec."
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -40,5 +40,7 @@ try {
write-output $TargetLanguage" : "$Result
}
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -21,5 +21,7 @@ try {
$SpeechSynthesizer.Speak($Text)
$SpeechSynthesizer.Dispose()
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -61,5 +61,7 @@ try {
echo "Sorry, hostname $Hostname is unknown."
pause
exit 1
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -33,5 +33,7 @@ try {
echo "WEATHER ALERT: $Result"
}
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -11,5 +11,7 @@ $GeoLocation="" # empty means determine automatically
try {
(Invoke-WebRequest http://v2d.wttr.in/$GeoLocation -UserAgent "curl" ).Content
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -15,5 +15,7 @@ try {
(Invoke-WebRequest http://wttr.in/${City}?format="* %l:+%c+%t+%p+%h+%P+%w +%S ->+%s" -UserAgent "curl" ).Content
}
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -11,5 +11,7 @@ $GeoLocation="" # empty means determine automatically
try {
(Invoke-WebRequest http://wttr.in/$GeoLocation -UserAgent "curl" ).Content
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}

View File

@ -14,5 +14,7 @@ if ($Path -eq "" ) {
try {
Compress-Archive -Path $Path -DestinationPath $Path.zip
exit 0
} catch { Write-Error $Error[0] }
exit 1
} catch {
Write-Error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}