mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-08-09 21:07:40 +02:00
Updated clean-repo.ps1 and kill-process.ps1
This commit is contained in:
@ -22,6 +22,8 @@
|
|||||||
param([string]$path = "$PWD")
|
param([string]$path = "$PWD")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
|
|
||||||
Write-Host "⏳ (1/4) Searching for Git executable... " -noNewline
|
Write-Host "⏳ (1/4) Searching for Git executable... " -noNewline
|
||||||
& git --version
|
& git --version
|
||||||
if ($lastExitCode -ne 0) { throw "Can't execute 'git' - make sure Git is installed and available" }
|
if ($lastExitCode -ne 0) { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||||
@ -42,7 +44,8 @@ try {
|
|||||||
& git -C "$path" submodule foreach --recursive git clean -xfd -f # to delete all untracked files in the submodules
|
& git -C "$path" submodule foreach --recursive git clean -xfd -f # to delete all untracked files in the submodules
|
||||||
if ($lastExitCode -ne 0) { throw "'git clean' in the submodules failed with exit code $lastExitCode" }
|
if ($lastExitCode -ne 0) { throw "'git clean' in the submodules failed with exit code $lastExitCode" }
|
||||||
|
|
||||||
"✅ Repo '$repoName' is clean now."
|
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||||
|
"✅ Repo '$repoName' cleaned in $($elapsed)s."
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
@ -1,35 +1,26 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Kills all local processes matching the given name
|
Kills local processes
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
← enter a detailed description of the script here
|
This PowerShell script stops all local processes matching the given name
|
||||||
.PARAMETER
|
.PARAMETER processName
|
||||||
← enter the description of a parameter here (repeat the .PARAMETER for each parameter)
|
Specifies the process name (ask user by default)
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
← enter a sample command that uses the script, optionally followed by sample output and a description (repeat the .EXAMPLE for each example)
|
PS> ./kill-process.ps1
|
||||||
.NOTES
|
|
||||||
Author: ← enter full name here
|
|
||||||
License: ← enter license here
|
|
||||||
.LINK
|
.LINK
|
||||||
← enter URL to additional information here
|
https://github.com/fleschutz/PowerShell
|
||||||
|
.NOTES
|
||||||
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
param([string]$processName = "")
|
||||||
param(
|
|
||||||
# [Parameter(Mandatory,ParameterSetName='ByProcessName')]
|
|
||||||
[string]$ProcessName = $(Read-Host -Prompt 'Enter the process name'))
|
|
||||||
|
|
||||||
function KillProcesses {
|
|
||||||
Write-Host -BackgroundColor Yellow -ForegroundColor Red "Process to kill: $ProcessName"
|
|
||||||
Get-Process | Where-Object -FilterScript {$_.processname -eq $ProcessName} | Select-Object id | Stop-Process
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
KillProcesses -ProcessName $processName
|
if ($processName -eq "") { $processName = Read-Host "Enter the process name" }
|
||||||
|
Get-Process | Where-Object -FilterScript {$_.processname -eq $processName} | Select-Object id | Stop-Process
|
||||||
"✔️ Done."
|
"✔️ Done."
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ ERROR: $($Error[0])"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user