Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell in NonInteractive mode

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?

like image 452
tobre Avatar asked May 16 '13 06:05

tobre


2 Answers

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.

like image 147
Davor Josipovic Avatar answered Sep 17 '22 22:09

Davor Josipovic


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.

like image 42
gek Avatar answered Sep 21 '22 22:09

gek