mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-03-25 21:46:43 +01:00
Updated the scripts
This commit is contained in:
parent
5c99f042c4
commit
8ace5fcff2
@ -6,4 +6,4 @@
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
./close-program "chrome"
|
||||
./close-program "chrome" "Google Chrome"
|
||||
|
@ -6,4 +6,4 @@
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
./close-program "msedge"
|
||||
./close-process "msedge" "Microsoft Edge"
|
||||
|
@ -6,4 +6,4 @@
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
./close-program "explorer"
|
||||
./close-process "explorer" "File Explorer"
|
||||
|
@ -1,31 +1,34 @@
|
||||
#!/snap/bin/powershell
|
||||
<#
|
||||
.SYNTAX ./close-program.ps1 [<program-name>]
|
||||
.DESCRIPTION closes the given program gracefully
|
||||
.SYNTAX ./close-program.ps1 [<program-name>] [<full-program-name>]
|
||||
.DESCRIPTION closes the processes of the given program gracefully
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param([string]$ProgramName)
|
||||
param([string]$ProgramName = "", [string]$FullProgramName = "")
|
||||
|
||||
try {
|
||||
if ($ProgramName -eq "" ) {
|
||||
Get-Process | Where-Object {$_.mainWindowTitle} | Format-Table Id, Name, mainWindowtitle -AutoSize
|
||||
$ProgramName = read-host "Enter program to close"
|
||||
if ($ProgramName -eq "") {
|
||||
get-process | where-object {$_.mainWindowTitle} | format-table Id, Name, mainWindowtitle -AutoSize
|
||||
$ProgramName = read-host "Enter program name"
|
||||
}
|
||||
if ($FullProgramName -eq "") {
|
||||
$FullProgramName = $ProgramName
|
||||
}
|
||||
|
||||
$Processes = Get-Process -name $ProgramName -erroraction 'silentlycontinue'
|
||||
$Processes = get-process -name $ProgramName -errorAction 'silentlycontinue'
|
||||
foreach ($Process in $Processes) {
|
||||
$_.CloseMainWindow() | Out-Null
|
||||
}
|
||||
start-sleep -milliseconds 100
|
||||
Stop-Process -name $ProgramName -force -erroraction 'silentlycontinue'
|
||||
stop-process -name $ProgramName -force -errorAction 'silentlycontinue'
|
||||
|
||||
$ProcessCount = $Processes.Count
|
||||
if ($ProcessCount -eq 0) {
|
||||
throw "program '$ProgramName' is not started yet"
|
||||
throw "$FullProgramName is not started yet"
|
||||
}
|
||||
write-output "OK - program '$ProgramName' with $ProcessCount process(es) has been closed."
|
||||
write-output "OK - $FullProgramName with $ProcessCount process(es) has been closed."
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
@ -6,4 +6,4 @@
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
./close-program "thunderbird"
|
||||
./close-program "thunderbird" "Mozilla Thunderbird"
|
||||
|
@ -6,4 +6,4 @@
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
./close-program "WindowsTerminal"
|
||||
./close-program "WindowsTerminal" "Windows Terminal"
|
||||
|
Loading…
Reference in New Issue
Block a user