Rundeck (Open Source) - How to Execute PowerShell script (In-Line or Command or File)

693 views
Skip to first unread message

naveen krishna vadakoppula

unread,
Sep 7, 2020, 12:02:05 PM9/7/20
to rundeck-discuss
Hi Team,

I have followed some other conversation for this issue on how to execute Powershell script (In-Line/Command/File). 

I have followed all the steps, But still facing issues and error is definetely related to My Rundeck config, But I need some help here.

Rundeck - 3.3.2 - Open Source (CentOS)
Project settings:
node-executor - WinRM
file-copier - WinRM

i see below error when executing a powershell script on remote windows node (In-Line/File/Command)

ERROR:
[overthere-winrm:XXXXXXXXX] Destination file acquired C:\rundeck\18-38- XXXXXXXXX-dispatch-script.tmp.ps1
[overthere-winrm: XXXXXXXXX  ] Copying file to C:\rundeck\18-38- XXXXXXXXX  -dispatch-script.tmp.ps1
[overthere-winrm: XXXXXXXXX  ] File copied at: C:\rundeck\18-38- XXXXXXXXX  -dispatch-script.tmp.ps1
[overthere-winrm: XXXXXXXXX  ] Closing connection
[overthere-winrm: XXXXXXXXX  ] powershell chmod +x C:\rundeck\18-38- XXXXXXXXX  -dispatch-script.tmp.ps1

'powershell' is not recognized as an internal or external command,
Debug is true storeKey false useTicketCache false useKeyTab false doNotPrompt false ticketCache is null isInitiator true KeyTab is null refreshKrb5Config is true principal is null tryFirstPass is false useFirstPass is false storePass is false clearPass is false
operable program or batch file.

Thank you
Naveen



rac...@rundeck.com

unread,
Sep 8, 2020, 8:01:23 AM9/8/20
to rundeck-discuss

Hi,

You can try with PyWinRM plugin (out of the box with Rundeck, “overthere winrm” plugin is outdated right now) which supports Kerberos by default and is under active development. I leave a basic job definition example to call the PowerShell.exe command.


<joblist>
  <job>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <dispatch>
      <excludePrecedence>true</excludePrecedence>
      <keepgoing>false</keepgoing>
      <rankOrder>ascending</rankOrder>
      <successOnEmptyNodeFilter>false</successOnEmptyNodeFilter>
      <threadcount>1</threadcount>
    </dispatch>
    <executionEnabled>true</executionEnabled>
    <id>7fe85de3-dfa3-441d-a427-6fb7ad45668a</id>
    <loglevel>INFO</loglevel>
    <name>PowerSHELLTest</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <nodefilters>
      <filter>name: windows</filter>
    </nodefilters>
    <nodesSelectedByDefault>true</nodesSelectedByDefault>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <exec>powershell.exe Write-Host "hello world!"</exec>
      </command>
      <command>
        <fileExtension>.ps1</fileExtension>
        <script><![CDATA[Write-Host "hello world!"]]></script>
        <scriptargs />
        <scriptinterpreter>powershell.exe</scriptinterpreter>
      </command>
    </sequence>
    <uuid>7fe85de3-dfa3-441d-a427-6fb7ad45668a</uuid>
  </job>
</joblist>

Here the result.

Hope it helps!

naveen krishna vadakoppula

unread,
Sep 8, 2020, 12:00:37 PM9/8/20
to rundeck...@googlegroups.com
Hi Team,

Thank you for your response. But the issues still persists even though I'm using PyWinRM

Please help me with this

PFB, The glimpse of errors:

[DEBUG ] handle_response(): returning <Response [200]> (kerberos_.py:412)[requests_kerberos.kerberos_]
[ERROR ] Execution finished with the following error (winrm-exec.py:286)[root]
[ERROR ] 'powershell' is not recognized as an internal or external command,
operable program or batch file.
(winrm-exec.py:287)[root]
[WinRMPython]: result code: 1, success: false
Failed: NonZeroResultCode: [WinRMPython] Result code: 1




--
You received this message because you are subscribed to the Google Groups "rundeck-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rundeck-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rundeck-discuss/84e6f9fb-e681-41b0-bf79-f340cfd54e59n%40googlegroups.com.
Message has been deleted

rac...@rundeck.com

unread,
Sep 8, 2020, 12:38:59 PM9/8/20
to rundeck-discuss

Hi,

Your project is configured to use “WInRM Node Executor Python”? (Project Settings -> Edit Configuration -> Default Node Executor -> WInRM Node Executor Python?. Additionally, make sure that you’re not missing the PowerShell path on your environment (also works if you pass the full powershell.exe path on “Invocation String”, usually at C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe).

<joblist>
  <job>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <dispatch>
      <excludePrecedence>true</excludePrecedence>
      <keepgoing>false</keepgoing>
      <rankOrder>ascending</rankOrder>
      <successOnEmptyNodeFilter>false</successOnEmptyNodeFilter>
      <threadcount>1</threadcount>
    </dispatch>
    <executionEnabled>true</executionEnabled>

    <id>edac37ca-fc40-4d77-94ac-ab3127fd5c0f</id>

    <loglevel>INFO</loglevel>
    <name>PowerSHELLTest</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <nodefilters>
      <filter>name: windows</filter>
    </nodefilters>
    <nodesSelectedByDefault>true</nodesSelectedByDefault>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>

        <fileExtension>.ps1</fileExtension>
        <script><![CDATA[Write-Host "hey"]]></script>
        <scriptargs />
        <scriptinterpreter>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</scriptinterpreter>
      </command>
    </sequence>
    <uuid>edac37ca-fc40-4d77-94ac-ab3127fd5c0f</uuid>
  </job>
</joblist>

Hope it helps!

Reply all
Reply to author
Forward
0 new messages