mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-26 01:43:37 +01:00
Added close-program.ps1 and close-windows-terminal.ps1
This commit is contained in:
parent
5c34261e5b
commit
a7bbbb99a7
@ -11,6 +11,8 @@ 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-program.ps1](Scripts/close-program.ps1) - closes the given program 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
|
||||||
* [display-time.ps1](Scripts/display-time.ps1) - displays the current time
|
* [display-time.ps1](Scripts/display-time.ps1) - displays the current time
|
||||||
|
29
Scripts/close-program.ps1
Executable file
29
Scripts/close-program.ps1
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
#!/snap/bin/powershell
|
||||||
|
|
||||||
|
# Syntax: ./close-program.ps1 [<program-name>]
|
||||||
|
# Description: closes the given program gracefully
|
||||||
|
# Author: Markus Fleschutz
|
||||||
|
# Source: github.com/fleschutz/PowerShell
|
||||||
|
# License: CC0
|
||||||
|
|
||||||
|
param([string]$ProgramName)
|
||||||
|
|
||||||
|
try {
|
||||||
|
if ($ProgramName -eq "" ) {
|
||||||
|
Get-Process | Where-Object {$_.mainWindowTitle} | Format-Table Id, Name, mainWindowtitle -AutoSize
|
||||||
|
$ProgramName = read-host "Enter program to close"
|
||||||
|
}
|
||||||
|
$List = Get-Process -name $ProgramName -erroraction 'silentlycontinue'
|
||||||
|
$NumProc = 0
|
||||||
|
$List | Foreach-Object { $NumProc++; $_.CloseMainWindow() | Out-Null } | stop-process -force
|
||||||
|
if ($NumProc -eq 0) {
|
||||||
|
write-error "ERROR: No processes for program '$ProgramName' found"
|
||||||
|
exit 1
|
||||||
|
} else {
|
||||||
|
write-output "Done - $NumProc processes stopped."
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
exit 1
|
||||||
|
}
|
15
Scripts/close-windows-terminal.ps1
Executable file
15
Scripts/close-windows-terminal.ps1
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
#!/snap/bin/powershell
|
||||||
|
|
||||||
|
# Syntax: ./close-windows-terminal.ps1
|
||||||
|
# Description: closes the Windows Terminal program gracefully
|
||||||
|
# Author: Markus Fleschutz
|
||||||
|
# Source: github.com/fleschutz/PowerShell
|
||||||
|
# License: CC0
|
||||||
|
|
||||||
|
close-program.ps1 "WindowsTerminal"
|
||||||
|
#try {
|
||||||
|
# exit 0
|
||||||
|
#} catch {
|
||||||
|
# write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
# exit 1
|
||||||
|
#}
|
Loading…
Reference in New Issue
Block a user