Hi there
I'm trying to execute a Powershell script as a filter ... but can't do it directly.
I've tried
--filter "C:\ProgramData\E-MailRelay\MyScript.ps1"
with the default action on .ps1 files to be to open with C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
I've also tried
--filter "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file C:\ProgramData\E-MailRelay\MyScript.ps1"
The result in the log file is
emailrelay: 20231008.233910.179: info: new envelope file [emailrelay.22732.1696768728.1.envelope.new]
emailrelay: 20231008.233910.179: info: filter [MyScript.ps1]: [emailrelay.22732.1696768728.1]: running C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file C:\ProgramData\E-MailRelay\MyScript.ps1
emailrelay: 20231008.233910.217: warning: filter [MyScript.ps1] failed: exit code 1: [rejected]
emailrelay: 20231008.233910.218: info: filter [MyScript.ps1]: [emailrelay.22732.1696768728.1]: failed response=[rejected]
emailrelay: 20231008.233910.218: info: rejected by filter: [rejected]
emailrelay: 20231008.233910.218: info: tx>>: "452 rejected"
but the diagnostics I've put into the PowerShell script indicate that the script is not being loaded so I'm not sure how it gets an exit code 1 unless that's the hard-coded result when a script can't be found/loaded/run.
The only way I've been able to get it to run is to use
--filter "C:\ProgramData\E-MailRelay\runscript.bat"
with the .bat file containing
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file C:\ProgramData\E-MailRelay\MyScript.ps1 %1 %2
It works but it's clumsy.
Is there a way to run a PowerShell script as a filter?
Thanks in advance
David
The "--filter" option takes an executable or batch-file path as its argument, so there is no shell-like interpretation where you can have an executable followed by space-separated arguments. If the filter argument has some extension other than .exe or .bat then emailrelay prepends "windows\system32\cscript.exe //B //nologo". That means that you can have a script as the --filter argument as long as there is a corresponding scripting engine registered (vbscript and javascript built-in by default, but also activestate perl and presumably therefore activestate python). You could make the case for doing the same thing for powershell, but as things stand, I think you have the least-bad solution.
I've opened a separate feature request for this.