Have created exchange script to monitor server health check. The script can be run through exchange management shell with no issue and send email html report as expected. But When i am scheduling using task scheduler i get no error message in history tab.
Below are details mention in task scheduler
action tab - program/script :- c:\windows\sysytem32\Windowspowershell\v.1.0\powershell.exe
Add argument (optional) :- -file ""
The script runs well in exchange management shell but not in task scheduler using the above way. Is there any ways where we can run script using exchange management shell using task scheduler so that it works expected
Any help suggestions or screenshot will be helpful.
Related
I'm looking for the best solution for automating Windows server 2012r2 via Rundeck. I'm extremely familiar with Rundeck but use it for linux vms. I've searched online for this topic but havent found anything that seems reliable. Ideally, I want to start a Runeck Job that can add users in Active Directory but not sure how to approach it. I've tried using winrm but have gotten mixed results. Ironically, it will run basic powershell commands but it errors when trying to do anything with AD. Ive even tried creating a powershell script on the AD server and have Rundeck simply execute the powershell script to no avail. Hopefully someone has had success in controlling windows nodes with Rundeck. Below is the error i receive when trying to run a powershell script.
Execution failed: 27 in project windows: [Workflow result: , step failures: {1=Dispatch failed on 1 nodes: [Windows_AD_Server: NonZeroResultCode: [WinRMPython] Result code: 1 + {dataContext=MultiDataContextImpl(map={ContextView(node:Windows_AD_Server)=BaseDataContext{{exec={exitCode=1}}}, ContextView(step:1, node:Windows_AD_Server)=BaseDataContext{{exec={exitCode=1}}}}, base=null)} ]}, Node failures: {Windows_AD_Server=[NonZeroResultCode: [WinRMPython] Result code: 1 + {dataContext=MultiDataContextImpl(map={ContextView(node:Windows_AD_Server)=BaseDataContext{{exec={exitCode=1}}}, ContextView(step:1, node:Windows_AD_Server)=BaseDataContext{{exec={exitCode=1}}}}, base=null)} ]}, status: failed]
Firstly, PowerShell already offers a built-in way to execute jobs, with no 3rd party addons.
About Jobs
Provides information about how PowerShell background jobs run a command or expression in the background without interacting with the current session.
About Remote Jobs
Describes how to run background jobs on remote computers.
PowerShell Jobs Week: Remote Jobs
I've never heard of / used Rundeck as Paul points out as well, so this just be the Rundeck has particulars that need to be in play first. Yet, looking at the docs, and a quick youtube video on the topic, there are several things that must be in place for what you say here...
I've tried using winrm but have gotten mixed results.
… to work.
Video - Running commands remotely using the console with WinRM/WinRS
If Rundeck is similar to SCCM or Scheduled Task, then the same approach applies.
Write Your PowerShell script. have Rundeck/ScheduedTask call powershell.exe to run the script
How to execute a PowerShell script automatically using Windows task scheduler?
Also, this could very well be seen as a duplicate of this stackoverflow discussion and answer.
rundeck unable to execute powershell script with import-module
I am setting up somethin similar and have the same problem. The AD operation executes successfully, but returns exit code 1 and throw the error you mentioned. I am in the process of debugging the plugin, but it seems there is a bug within response handling.
Please check if the ad operation works although the error is thrown and please post the script block you are using to control the AD.
Edit: in meantime I was able to narrow down the issue and opened an issue with the project: github
I provisionally fixed the issue with adding the following line in winrm-session.py after line 89:
new_msg = msg
The line before is:
" error message: %s" % (e))
The line after is:
else:
If this does not solve your issue, please post your script block.
Best Tobias
I use a python script to send mails. The script runs a VBA macro.
I'm scheduling the python script to run at a particular time.
Configuration
My trust settings in Outlook has all macros enabled.
I'm running the task with highest priority too.
Problem
I am able to send mails if I run the script manually.
However, when I try to run it via Windows Task Scheduler, mails are not being sent.
Try a different scheduler and see if this works.
For example Splinterware system scheduler.
Trying a different scheduler can help you figure out if the problem is
a setting in the scheduler (like not having the password entered)
or in your Python script (which would affect all schedulers)
There is a way to send emails from Outlook automatically without the use of Task Scheduler. It is outlined neatly here.
It uses recurring reminders, so Outlook must be kept running at all times (but the macro is only executed when the reminder fires).
I need to start up Outlook via Powershell script and schedule it.
The Powershell script is able to start Outlook when its run manually from powershell command prompt.
But when the same script is run via windows task scheduler I only see the process kicking off in background while there is no running instance of Outlook in the front end.
I wanted to know why the app is not launching at the front end.
Check what user the scheduled task is running as, unless it's running as the logged in user you won't see anything.
Outlook will launch, as a background process, but as it will be running as another user (likely system) you won't see the outlook window.
I have written a PowerShell script that starts a c# console app. The functionality of this console app will only work if it runs as administrator.
After code deploy by AWS code pipeline/code deploy service, I want to automatically run this c# console app with administrative privilege.
Is there any approach to do this.
You can create a scheduled task that runs your ps1 script on demand with administrative privileges. Then you can create shortcut or start the task from console or another script. Since user credentials are stored in task itself, it will work without UAC prompt.
For my project purposes, we need to schedule a job which invokes an C# exe file.
I know that we can have a batch file to invoke the exe file and schedule it using TWS.
I just want to know whether we can directly invoke an exe file from TWS
TWS stands for Tivoli Workload Scheduler. It is now marketed by IBM as Tivoli Workload Automation.
Yes you can schedule a job which invokes an exe file. Basically, TWS emulates what a user is doing in a interactive session. If you can log to a server, start a command prompt and start you exe (and append arguments as needed), then TWS will do the same if you code the job right. It will provide you logs and return code handling too.