rundeck-plugins / rundeck-winrm-plugin

UNMAINTAINED - Rundeck WinRM Node Executor plugin
Other
56 stars 28 forks source link

powershell script with arguments which has spaces not working as expected #61

Open gangadhar01a opened 5 years ago

gangadhar01a commented 5 years ago

Hi,

I am executing the following powershellscript via rundeck to stop the service

"$serviceName=$args[0] $id=Get-WmiObject -Class Win32_Service -Filter "Name LIKE '$serviceName'" $id.ProcessId taskkill /pid $id.ProcessId /F"

Created a field called "serviceName" in rundeck job.

The entire job works as expected for all services expect the service which has spaces example: if the serviceName is "Advantage Platform License Service"

This resulted in following error in "LogOutput"

_09:08:53   1. Command Get-WmiObject : Invalid query "select * from Win32_Service where Name LIKE
09:08:53     ''Advantage'"
09:08:53     At \corpshares\tech\DevOps\Rundeck\scripts\killService.ps1:2 char:5
09:08:53     + $id=Get-WmiObject -Class Win32_Service -Filter "Name LIKE '$serviceNa ...
09:08:53     + ~~~~~~~~~~~~~
09:08:53     + CategoryInfo : InvalidArgument: (:) [Get-WmiObject], Management
09:08:53     Exception
09:08:53     + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.C
09:08:53     ommands.GetWmiObjectCommand_

Not sure why rundeck added a single quote at the beginning of Advantage .

Things which I have tried, I have changed the input to "Advantage%[ ]%Platform%[ ]%License%[ ]%Service"

This time the following error showed up

_08:40:16   1. Command Get-WmiObject : Invalid query "select * from Win32_Service where Name LIKE
08:40:16     ''Advantage%['"
08:40:16     At \corpshares\tech\DevOps\Rundeck\scripts\killService.ps1:2 char:5
08:40:16     + $id=Get-WmiObject -Class Win32_Service -Filter "Name LIKE '$serviceNa ...
08:40:16     + ~~~~~~~~~~~~~
08:40:16     + CategoryInfo : InvalidArgument: (:) [Get-WmiObject], Management
08:40:16     Exception
08:40:16     + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.C
08:40:16     ommands.GetWmiObjectCommand_

Again I have noticed the single quote at the beginning of "Advantage%[" - This may be he reason why rundeck unable to execute the script.

I have manually executed the script with input "Advantage%[ ]%Platform%[ ]%License%[ ]%Service" on the server, which has worked without any issues.

ledufakademy commented 3 years ago

Same issue here with robocopy command in Powershell script : if unc path have space : Rundeck is out of order ! [WinRMPython] execCommand started, command: PowerShell.exe -executionpolicy bypass C:\WINDOWS\TEMP\0-1596-srv1.domain.com-robocopy-rundeck.ps1.PS1 ''"'"'\\srv1.domain.com\Modèles de documents'"'"'' ''"'"'\\nas2.domain.com\Share\Modèles de documents**'"'"''

Then we got this :
[DEBUG ] SPNEGO step output: (_negotiate.py:135)[spnego._negotiate] [DEBUG ] Sending encrypted credentials (credssp.py:165)[requests_credssp.credssp] [WinRMPython]: result code: 1, success: false [WinRMPython] execCommand started, command: del C:\WINDOWS\TEMP\0-1596-srv1.domain.com-robocopy-rundeck.ps1.PS1 [WinRMPython] executing: [[${config.interpreter}, -u, /var/lib/rundeck/libext/cache/py-winrm-plugin-2.0.14/winrm-exec.py, ${node.hostname}]]

execution overview : $ PowerShell.exe -executionpolicy bypass scriptfile.PS1 "'\srv1.domain.com\Modèles de documents'" "'\nas1.domain.com\AMC-Birieux\Modèles de documents'"

Note : quote and double quote , when copy/paste this exact command under target node : it's working perfectly !

ledufakademy commented 3 years ago

oups ... there also ... an encoding issue when using "é" accented chararcter . Rundeck + powershell = the Hell !