From a0fdc0d5f3cf240c2d2701659c15ecc2390367e5 Mon Sep 17 00:00:00 2001 From: Shawn Melton Date: Fri, 25 Oct 2019 13:43:34 -0500 Subject: [PATCH] added logic on process message --- cleanup.ps1 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cleanup.ps1 b/cleanup.ps1 index 5ecc331e0d..c722a0649c 100644 --- a/cleanup.ps1 +++ b/cleanup.ps1 @@ -47,11 +47,13 @@ if ( ($olderVersions.Count -gt 0) -and $newestVersion.Version -in $installedVers } else { $processes = Get-Process $process -ErrorAction SilentlyContinue | Where-Object Id -NE $PID } - if ($Pscmdlet.ShouldProcess("$env:COMPUTERNAME", "Killing $($processes.Count) processes of powershell running")) { - Write-Output "Death to the following process(es): $(($processes.Id) -join ",")" - $processes | Stop-Process -ErrorVariable dangit -ErrorAction SilentlyContinue -Force - if ($dangit) { - Write-Warning "Not able to kill following processes: $((Get-Process $process | Where-Object Id -NE $pid).Id -join ",")" + if ($processes.Count -gt 0) { + if ($Pscmdlet.ShouldProcess("$env:COMPUTERNAME", "Killing $($processes.Count) processes of powershell running")) { + Write-Output "Death to the following process(es): $(($processes.Id) -join ",")" + $processes | Stop-Process -ErrorVariable dangit -ErrorAction SilentlyContinue -Force + if ($dangit) { + Write-Warning "Not able to kill following processes: $((Get-Process $process | Where-Object Id -NE $pid).Id -join ",")" + } } } if ($Pscmdlet.ShouldProcess("$env:COMPUTERNAME", "Removing old versions of $module.")) {