Immutable solution version
Powershell in NonInteractive mode
Complete solution
Run with -Force : Stop-Process -InputObject $prc -ErrorAction SilentlyContinue -Force As C.B.
Run with -Force : Stop-Process -InputObject $prc -ErrorAction SilentlyContinue -Force As C.B. suggested in the comment: -confirm:$false should also work. Rationale for this is as follows: -Confirm is a switch parameter. Switch parameters can only take arguments if you specify the parameter with a trailing colon and a value.
Context: I use Octopus for our deployments. I have a problem with one of the Powershell scripts to control the deployment: # stops running processes $processes = @("Notepad", "Firefox") foreach ($process in $processes) { $prc = Get-Process -Name $process -ErrorAction SilentlyContinue if (-not($prc -eq $null)) { Write-Host "Stopping " $prc.ProcessName Stop-Process -InputObject $prc -ErrorAction SilentlyContinue } } The programs I try to stop are not the ones you see in the script above
Evidence
Source: I use Octopus for our deployments. I have a problem with one of the Powershell scripts to control the deployment: # stops running processes $processes = @("Notepad", "Firefox") foreach ($process in $processes) { $prc = Get-Process -Name $process -ErrorAction SilentlyContinue if (-not($prc -eq $null)) { Write-Host "Stopping " $prc.ProcessName Stop-Process -InputObject $prc -ErrorAction SilentlyContinue } } The programs I try to stop are not the ones you see in the script above
Verified resolution: Run with -Force : Stop-Process -InputObject $prc -ErrorAction SilentlyContinue -Force As C.B. suggested in the comment: -confirm:$false should also work. Rationale for this is as follows: -Confirm is a switch parameter. Switch parameters can only take arguments if you specify the parameter with a trailing colon and a value.
Source URL: https://stackoverflow.com/questions/16580723/powershell-in-noninteractive-mode
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_WW4ZvaQ4It-y9fQoSCr5HA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Powershell in NonInteractive mode <span>— Vectle</span></a>