Typically you would attach the .ps1 script to the task and run it using the following commandline:
%systemdrive%\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nologo -executionpolicy bypass -noprofile -file Powershellscript.ps1
However, the following demonstrates why this will fail and how to resolve the issue.
Look at the XML file created by the task engine:
For images browse to:
\\ikbox\peinst\scripts\imagingtasks_ID#.xml
OR
\\ikbox\peinst\scripts\tasks_ID#.xml for scripted installs
ID# is the number of the deployment
eg: ikbox/setup_detail?boot_image_id=1 will be tasks_1.xml
Below is what you would see from the failed results in the xml file
powershell
%systemdrive%\KACE\Applications\152
"%systemdrive%\KACE\Applications\152\%systemdrive%\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -nologo -executionpolicy bypass -noprofile -file Powershellscript.ps1 > c:\log.log]]>
Notice the added directory in front of the path provided in the command line, this is due to the task engine interpreting the .exe as being attached to the task and therefore is trying to run it directly from where it thinks the .exe exists.
A simple removal of .exe from the commandline will resolve the issue, so the task should now look like the following:
%systemdrive%\Windows\System32\WindowsPowerShell\v1.0\powershell -nologo -executionpolicy bypass -noprofile -file Powershellscript.ps1
And once saved, the XML will change to look like the following:
windows\system32\windowspowershell\v1.0\powershell -nologo -executionpolicy bypass -noprofile -file Powershellscript.ps1]]>CommandLine>
Note: