Search code examples
powershellactive-directorywinrmrundeck

How to control window AD with rundeck


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]

Solution

  • 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