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
Related
Rundeck 4.8.0 community version on Redhat 9 Linux with Windows node.
My Rundeck jobs call powershell (.ps1) scripts on the windows node.
If there are any errors encountered in the script, the Rundeck job dies.
The rundeck output gives the NonZeroResultCode message
NonZeroResultCode: [WinRMPython] Result code: 1
There's more code that needs to be run after where the error occurred, but Rundeck just dies and doesn't continue the rest of the .ps1.
I previously used Rundeck version 3.something, I thing it was 3.9.
If there was an error in the script, such as a get or a set failed, the Rundeck console would just display the text of the error in red, and continue.
Now I know I can change my code and add try/catch statements, -erroraction SilentlyContinue and so on. However it makes no sense to me that Rundeck takes it upon itself to kill my script because a get or a set failed.
I want to be the one to decide if I want to exit the script or not, I don't want Rundeck to make that decision.
Can this behavior be changed?
thanks in advance.
That's the default Rundeck behavior.
You can "attach" an error handler on that script-step (on any step actually), e.g: the error handler could be the script code when your step fails.
The error handler feature is designed for that kind of scenario, take a look at this.
I'm troubleshooting an Selenium script that runs through the Task Scheduler on a Windows Server. It's running in PowerShell using version 3.0.1 of the Selenium module (found here:https://www.powershellgallery.com/packages/Selenium/3.0.1) with the Edge browser (the one with Chromium).
The "The HTTP request to the remote WebDriver server for URL [localhost] timed out after 60 seconds." error has been quite persistent and only appears when run through the Task Scheduler. The script runs fine when running manually through ISE.
Also to note, there's another script that is more or less the same as the one having the issue, albeit using a slightly different url (same site). This second script runs without issue through the task scheduler. They're performing the same sequence of actions which is why I'm not entirely sure why it would fail for one script but not the other.
I haven't found a suitable solution while looking at other posters facing the same issue. Any help is much appreciated!
I had the same issue. I tried all kinds of code changes but the only step that worked for me was to change the Security Options in Task Scheduler.
Task (right-click) > Properties > General > Switch from Run whether user is logged on or not to Run only when the user is logged on.
I guess this would be a temporary solution. I'll keep looking and update this if I find a better solution.
This might be a very basic question. I have FileWatcher script in windows powershell which I want to run always so that it keeps watching a particular location for files. when I run it from Windows Powershell IDE its run perfectly fine. I understand that I can schedule a task in windows task scheduler for that but what's happening is that the task runs and then comes back in "Ready" status. This is NOT working. I think it should be in "Running" state always. I might be missing something. Please kindly help with your valuable suggestions.
You can do this with TaskSchedule…
Running PowerShell scripts as a “service” (Events: Prologue)
but this is also what permanent Event Subscriptions are for or setting up as user10675448 suggest, make it a real service.
How to run a PowerShell script as a Windows service
Windows PowerShell - Writing Windows Services in PowerShell
This article presents the end result of that effort: A novel and easy
way to create Windows Services, by writing them in the Windows
PowerShell scripting language. No more compilation, just a quick
edit/test cycle that can be done on any system, not just the
developer’s own.
There is also this approach...
PowerShell and Events: Permanent WMI Event Subscriptions
Unlike the temporary event, the permanent event is persistent object
that will last through a reboot and continue to operate until it has
been removed from the WMI repository.
There are multiple ways of setting up the WMI events and I will be
covering 3 of those ways (as they deal with PowerShell) in this
article.
I am working on a mid-size Windows 2012 R2 domain right now, and slapped together a PowerShell login script.
But I can't figure out how to allow regular users to run it!
By default, PowerShell script execution is disabled in a Windows domain.
I am trying to enable script execution using group policies.
I found several sets on instructions, but none have yet yielded the result desired. Here is an example of the instructions I have found:
https://blogs.technet.microsoft.com/poshchap/2015/01/02/execution-policy-and-group-policy/
So far no amount of gpupdate /force or rebooting seems to work.
Does anyone have first hand experience at enabling script execution using group policies?
I have a powershell script that runs for ~30 minutes (waiting on various process' to finish). At the end, it writes a message to the event log, determining if the process was a success or failure. I plan on hosting this script on teamcity and want the build to fail, but don't know how to handle the interaction between the script and teamcity in order for this to happen.
I'm looking for a way to make a powershell script that is ran remotely to communicate to teamcity whether it was a failure or success. I've read up on a lot of the teamcity documentation and I'm still not sure how to start going about this.
You should probably consider using TeamCity Service Messages, or specifically Reporting Build Problems.
An example of how to emit a service message using PowerShell (assuming you're using the PowerShell build step):
Write-Output "##teamcity[buildStatus text='I am a successful build']"
or
Write-Output "##teamcity[buildProblem description='$powershell_error_message']"
where you can inject the captured powershell error message.
To intentionally fail a build in teamcity you should use "[Environment] :: Exit (1)" instead of "Exit 1".
More information can be obtained at the link below:
https://confluence.jetbrains.com/display/TCD9/PowerShell