Added close-chrome.ps1 and close-thunderbird.ps1

This commit is contained in:
Markus Fleschutz 2020-12-28 08:40:26 +00:00
parent 519fbbb709
commit 4946b67d1f
5 changed files with 34 additions and 16 deletions

View File

@ -11,7 +11,9 @@ The following PowerShell scripts can be found in the [Scripts/](Scripts/) subfol
* [check-mac-address.ps1](Scripts/check-mac-address.ps1) - checks the given MAC address for validity * [check-mac-address.ps1](Scripts/check-mac-address.ps1) - checks the given MAC address for validity
* [check-xml-file.ps1](Scripts/check-xml-file.ps1) - checks the given XML file for validity * [check-xml-file.ps1](Scripts/check-xml-file.ps1) - checks the given XML file for validity
* [clone-repos.ps1](Scripts/clone-repos.ps1) - clones well-known Git repositories * [clone-repos.ps1](Scripts/clone-repos.ps1) - clones well-known Git repositories
* [close-chrome.ps1](Scripts/close-chrome.ps1) - closes Google Chrome gracefully
* [close-program.ps1](Scripts/close-program.ps1) - closes the given program gracefully * [close-program.ps1](Scripts/close-program.ps1) - closes the given program gracefully
* [close-thunderbird.ps1](Scripts/close-thunderbird.ps1) - closes Mozilla Thunderbird gracefully
* [close-windows-terminal.ps1](Scripts/close-windows-terminal.ps1) - closes Windows Terminal gracefully * [close-windows-terminal.ps1](Scripts/close-windows-terminal.ps1) - closes Windows Terminal gracefully
* [configure-git.ps1](Scripts/configure-git.ps1) - sets up the Git configuration * [configure-git.ps1](Scripts/configure-git.ps1) - sets up the Git configuration
* [csv-to-text.ps1](Scripts/csv-to-text.ps1) - converts the given CSV file into a text list * [csv-to-text.ps1](Scripts/csv-to-text.ps1) - converts the given CSV file into a text list

10
Scripts/close-chrome.ps1 Executable file
View File

@ -0,0 +1,10 @@
#!/snap/bin/powershell
# Syntax: ./close-chrome.ps1
# Description: closes Google Chrome gracefully
# Author: Markus Fleschutz
# Source: github.com/fleschutz/PowerShell
# License: CC0
$ExitCode = close-program.ps1 "chrome"
exit $ExitCode

View File

@ -14,15 +14,16 @@ try {
$ProgramName = read-host "Enter program to close" $ProgramName = read-host "Enter program to close"
} }
$List = Get-Process -name $ProgramName -erroraction 'silentlycontinue' $List = Get-Process -name $ProgramName -erroraction 'silentlycontinue'
$NumProc = 0 $NumProcKilled = 0
$List | Foreach-Object { $NumProc++; $_.CloseMainWindow() | Out-Null } | stop-process -force $List | Foreach-Object {
if ($NumProc -eq 0) { $_.CloseMainWindow() | Out-Null
write-error "ERROR: No processes for program '$ProgramName' found" $NumProcKilled++
exit 1 } | stop-process -force
} else { if ($NumProcKilled -eq 0) {
write-output "Done - $NumProc processes stopped." throw "program '$ProgramName' is not started yet"
exit 0
} }
write-output "OK - program '$ProgramName' has been closed ($NumProcKilled processes)."
exit 0
} catch { } catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1

10
Scripts/close-thunderbird.ps1 Executable file
View File

@ -0,0 +1,10 @@
#!/snap/bin/powershell
# Syntax: ./close-thunderbird.ps1
# Description: closes Mozilla Thunderbird gracefully
# Author: Markus Fleschutz
# Source: github.com/fleschutz/PowerShell
# License: CC0
$ExitCode = close-program.ps1 "thunderbird"
exit $ExitCode

View File

@ -1,15 +1,10 @@
#!/snap/bin/powershell #!/snap/bin/powershell
# Syntax: ./close-windows-terminal.ps1 # Syntax: ./close-windows-terminal.ps1
# Description: closes the Windows Terminal program gracefully # Description: closes Windows Terminal gracefully
# Author: Markus Fleschutz # Author: Markus Fleschutz
# Source: github.com/fleschutz/PowerShell # Source: github.com/fleschutz/PowerShell
# License: CC0 # License: CC0
close-program.ps1 "WindowsTerminal" $ExitCode = close-program.ps1 "WindowsTerminal"
#try { exit $ExitCode
# exit 0
#} catch {
# write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
# exit 1
#}