简体   繁体   中英

Scheduling PowerShell jobs in Control-M

I am facing this problem with Control-M.

I have created a simple PowerShell job and sceduled it in Control-M with Task Type as command. After executing, the job status become green but it does nothing it is expected to do. However, the job is executing fine when double clicked or when run with PowerShell.

For experiment, I created to simple batch script (.bat) to write to a file and scheduled it in Control-M. It does not run in Control-M (Even after becoming green).

I gave the command in the batch file directly at the command box of Control-M and it runs fine.

I tried with Job Type "Job" but it has the same problem.

Please someone help. Also, is there any special setting for PowerShell jobs in Control-M?

Bruno Brant is correct. You have to execute the script with the Powershell program.

powershell.exe -NoLogo -NonInteractive -NoProfile -ExecutionPolicy "Bypass" -File "[hidden unc path]\\HelloWorld.ps1"

Place an agent on a specified server. Have Control-M run the script from the server you placed the agent on. "Bypass" is only used to test the connection and that the test script runs. Remove it one the call is successful and test it again. On the Host machine (with Control-M agent) changed execution policy to 'remote-signed'. test again. If your script is on another computer, you can use a hidden unc path. If on the same machine, replace the path with local drive.

Email me and I can provide more info. If I have more time, I will post more information of what worked for me and what didn't.

You can't directly call Powershell scripts as if the where a executable.

CONTROL-M is probably calling you programs through cmd ("DOS"), which do not recognize PS1 files as a executable (maybe you can tweak that, but, by default, that will not happen). Inside Windows, indeed you may have a configuration (file association) that calls Powershell and pass the script to it.

In any case, what you need to do is call Powershell from CONTROL-M and pass your script as a parameter:

powershell -File yourscript.ps1 param1 param2 

For more info on this syntax, open cmd and type

powershell /?

I had a similar situation happen. Tried the powershell command all different ways without luck. Finally - I logged into the CCM, went to the agent properties that I was running the powershell command against and checked the "login as user" option. Turning this on corrected my issue where the job would submit and execute but didn't appear to be doing anything. Give this a try!

Are you running the powershell script in remote server? and how do you put the commandline in control m job.

Try this.

PowerShell FullPathtoFile.ps1 parameters 2>&1 | more

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM