Hi Rick, we now have some folks inquiring about whether cybAgents (via ESP) can schedule .ps1 files or not.
A few months back when we asked, CA suggested this type of job def:
nt_job cybwin2
cmdname C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
agent nt_xyz
user domain\userid
args '-ExecutionPolicy unrestricted' +
'-File D:\cyb_agent_R7\helloworld.ps1'
exitcode 1 success
exitcode 0 success
run any
endjob
The .ps1 runs just fine running the .ps1 from windows console but
Running this via cybAgent we're getting this in the spool
Unexpected token '-File D:\cyb_agent_R7\helloworld.ps1' in expression or state
ent.
At line:1 char:71
+ '-ExecutionPolicy unrestricted' '-File D:\cyb_agent_R7\helloworld.ps1' <<<<
+ CategoryInfo : ParserError: (-File D:\cyb_agent_R7\helloworld.p
s1:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
(This is on an R7 agent ...have not tried it on an R11 yet)
the .ps1 script consists of:
$strString = "Hello World"
write-host $strString
Exit 4
So, while awaiting (a few days) for CA to respond to that error, I saw your example in the Forum.
To reiterate, you only were able to get yours to work by employing
CMDNAME powershell.exe
ARGS /C <path to script>\hello.ps1 %USER1
RUN ANYDAY
ENDJOB
For PowerShell I needed to create 2 functions to get the correct behavior.
- EnablePowerShellOutput
- ExitWithCode
I'm really a bit disappointed that the cybAgent would require one to code a customized function in order to write output to
the agent's spool file for anything that works on the console, (we'd absolutely need echoing to the spoolfile for debugging the .ps1s) as well as requiring a customized function to set the return code (for example .vbs and cscript has a built in function for exitting with an errorcode...I thought powershell was supposed to supplant windows scripting host...seems like its a step backward).