36

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?

7
  • Can you post the value of get-executionpolicy and $confirpreference from the server with version 2.0? Commented May 16, 2013 at 7:03
  • get-executionpolicy RemoteSigned $confirpreference There was not output for $confirpreference. Commented May 16, 2013 at 7:59
  • Ops, my typo: $confirmpreference ... Commented May 16, 2013 at 8:06
  • 2
    try to add -confirm:$false to the stop-process cmdlet.. Commented May 16, 2013 at 8:29
  • 2
    I was able to try it today. The Stop-Process worked without a problem. It works with -Force, it works with -confirm:$false and with both together. Thank you! Commented May 22, 2013 at 15:23

3 Answers 3

40

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
Correction. Run with the -Force
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.
5

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.

Comments

0

I had this issue with running an inline PowerShell command on Azure Devops PowerShell deployment task. I could only fix the issue by running the PS command in a Command Line Script Task instead, see documentation here.

Add the following to the scripts field of the task for example:

Powershell -Command "Install-Module -Name SqlServer -Force -Confirm:$false"

In other words, put your PS command in double quotes, then run PowerShell -Command "MyPSCommand...".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.