Deploy- Windows PowerShell is in NonInteractive mode

Was trying to execute Powershell Script which was looking for multiple process with mutliple instances running on server and if they are running then it will stop the process, but I am getting below error while executingthe Script. I was able to execute the same Script locally without any errors but it was throwing error while deploying through Octopus

“Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available. Cannot find a process with the name “XYZZ”Verify the process name and call the cmdlet again.”

#Killing the process
#An array of Process.
$array = @(“XYZ”,“ABC”)

foreach ($process in $array)
{

$num = @(get-process -name $process -ErrorAction SilentlyContinue).count
Write-Verbose “Number of $Process Instances running on $env:Computername is $num” -verbose

If($num -gt '0'){

Write-Verbose "Stopping $process " -Verbose
Stop-Process -Name $process -Confirm:$false
Start-Sleep -Seconds 10
}
Else
{
Write-verbose "$Process doesnt exist " -Verbose
}

Hi,

When we run scripts in Octopus they have to be non-interactive (as the error suggests). It looks like Stop-Process needs the -Force option to make it non-interactive even if -Confirm:$false is set.

Try changing that line of your script to:

Stop-Process -Name $process -Force 

Regards,
Mark

Thanks Mark