1

Solution: Ended having to enable "Turn on Script Execution" in Group Policy. Located under Administrative Templates\Windows Components\Windows Powershell. Enable policy and set your desired execution policy.

Server 2008 R2

Utilizing file screen alerts and trying to execute a powershell script but cannot get it working for some reason.

I've been trying basic 1 line scripts ( log off a session ID) and it's not working. The alerts go through, but the script is not executed.

Here's the settings:

Settings

I've tried working directory in SysWoW, C:\, System32 nothing works and everything I read says it should.

Can anyone point out what I'm doing wrong?

Plasma
  • 19
  • 4
  • Is powershell not executing or is your script not processing what it should? What's the execution level set on this machine? What's the code of the actual script? – Colyn1337 Dec 18 '15 at 15:40
  • Are you receiving an error which you can post? – bentek Dec 18 '15 at 16:27
  • @Colyn1337 powershell is not executing. Execution level is set as unrestricted on this machine and run as System privileges. I've tried a simple 'stop-machine' or 'logoff 2' (where session ID 2 is logged in and uneffected) – Plasma Dec 19 '15 at 02:11
  • @bentek no errors, unfortunately. Nothing in event logs either, just the event for the file screen alert which **does** fire off, I receive the email alert but no script execution. Batch works fine though – Plasma Dec 19 '15 at 02:15
  • How do you have it set to trigger? – bentek Dec 19 '15 at 02:16
  • @bentek triggers when a matching filename/extension are detected being saved (message.txt in this case), shoots off an email and executes the script. Running as Local System, powershell level is unrestricted level on this machine. Also if I run the 1 line of code in the script just straight from powershell it works fine, which is why I think the it's either not executing or something is going wrong when it does somehow. Thanks – Plasma Dec 19 '15 at 02:25
  • Ok, but where do you have that trigger configured? Any more details you can share? – bentek Dec 19 '15 at 03:05
  • @bentek I'm not sure I follow. It's configured under a file screen, setup under File Server Resource Manager. Is that what you're asking? Under the command tab I've pointed it to powershell.exe in the SysWOW64 directory and in the arguments have it set as '-File C:\path\to\script.ps1'. I've placed the script in various directories to see it made a difference, such as the same directory as powershell.exe and System32, etc. Thanks – Plasma Dec 20 '15 at 21:10
  • Can you run the command with arguments in a scheduled task and get results? – McKenning Dec 21 '15 at 23:10
  • @McKenning Thanks for the comment, I actually ended up getting this resolved. It was due to a GPO setting that needed to be enabled for some reason, instead of being left as unconfigured. – Plasma Dec 22 '15 at 21:26

2 Answers2

0

This method worked for me

For a bit of background I wanted to creating a syslog message to be sent to a server when a quote got reached. I tested the script directly in powershell and worked.

  • Put the PS script file in the root folder where the Powershell EXE is. In my case the PS file is called syslogscript.ps1
  • In the Run a command or script field put %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe I am running server 2012 so may be different depending on your Windows build
  • In the command argument field powershell -executionpolicy bypass -File .\syslogscript.ps1
  • When I reached my quote the script executed
  • If you're bypassing the execution policy, that is the equivalent of enabling script execution. – Davidw Mar 16 '22 at 21:43
0

Solution: Ended having to enable "Turn on Script Execution" in Group Policy. Located under Administrative Templates\Windows Components\Windows Powershell. Enable policy and set your desired execution policy.

Plasma
  • 19
  • 4