34

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, but they represent what I am trying to do. Now the problem I have with it, is that it works well on one server, but not on another. Where it does not work, I get the error message:

Stop-Process : Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available.

The script that works runs on Powershell 3.0, the one that does not work on Powershell 2.0. I cannot upgrade to Powershell 3.0 everywhere yet because the old servers run with Windows Server 2003. How can I make it work on PS 2.0?

tobre
  • 1,347
  • 3
  • 21
  • 53

2 Answers2

36

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.

Cheeso
  • 189,189
  • 101
  • 473
  • 713
Davor Josipovic
  • 5,296
  • 1
  • 39
  • 57
  • I will give this a try as soon as I can. Our users are using the system frequently for testing and I cannot do deployments often. I ran the script this morning from Powershell ISE stopping Notepad and it worked well. Therefore the only way to check if the problem is resolved is to do an actual deployment. – tobre May 16 '13 at 07:28
  • 1
    Correction. Run with the `-Force` – Andrew Young Jun 01 '17 at 20:23
  • I had Remove-Item with -Force in a DevOps deployment powershell script but was still getting this message. So I'm going to try the -confirm:$false switch too. – Ian Yates Dec 08 '20 at 01:44
4

I just tried to use Remove-Item on the directory with children and got same message: Remove-Item : PowerShell is in NonInteractive mode. Read and Prompt functionality is not available. In my case -Recurse key has helped.

gek
  • 524
  • 6
  • 18