Automic Workload Automation

Expand all | Collapse all

Not able to pass password to powershell script

  • 1.  Not able to pass password to powershell script

    Posted Sep 12, 2018 06:09 AM

    Dear Experts,

     

    I am creating a windows job to execute the powershell script in AWA 12. I am facing issues when passing the password to powershell as powershell is not able to recognize the password. Please share your inputs to solve this issue.

     

    Below are the lines written in my script.

    :SET &LOGIN# = GET_LOGIN("LOGIN_TEST","*","win",PASSWORD)
    :print This is : &LOGIN#
    : SET &SecurePassword# = (&UC_JOBMD CMD="echo &LOGIN#")
    :print This is : &SecurePassword#
    :SET &URL# = "somepath"

     

    powershell -command D:\test\pstest\testing.ps1 -username "<ara_clnt>/<username>/<department>" -password &SecurePassword# -artifacturl &URL# -profile "someprofile"

     

    @set retcode=%errorlevel%
    @if NOT %ERRORLEVEL% == 0 goto :retcode

    The powershell script is calling an ARA object.

    When executing the job i am getting below error. Please check and share your views.

     

    C:\>powershell -command D:\test\pstest\testing.ps1 -username "<ara_clnt>/<username>/<department>"
    -password N -artifacturl &URL# -profile "someprofile" ConvertTo-SecureString : The parameter value "N" is not a valid encrypted  string.

    I have referred lot of pages in community for example  below.
    &UC_JOBMD -- decrypted password as parameter to powershell

    Thanks,
    Rajkumar Pandiaraja


  • 2.  Re: Not able to pass password to powershell script

    Posted Sep 12, 2018 02:01 PM

    Hi Rajkumar,

     

    I saw that this post was in the CA Automic Community and categorized as CA Application Manager, but from the description content, its about AWA/ARA.  As such, I have moved this post to the CA Automic Workload Automation space and shared with the ARA space to better reach the product user audience. 



  • 3.  Re: Not able to pass password to powershell script

    Posted Sep 13, 2018 03:57 AM

    Hi Rajkumar,

     

    1 - Does this section of the code return the actual password ? 

     

    :SET &LOGIN# = GET_LOGIN("LOGIN_TEST","*","win",PASSWORD)
    :print This is : &LOGIN#
    : SET &SecurePassword# = (&UC_JOBMD CMD="echo &LOGIN#")
    :print This is : &SecurePassword#

     

    2 - Are you running version 11.1 or higher ? 

    If so, please try pasting the Powershell script directly into a Windows job between :BEGIN_EXT_INT ... :END_EXT_INT tags.

     

    The command line 

    : SET &SecurePassword# = (&UC_JOBMD CMD="echo &LOGIN#")

    Can be run between these tags.

     

    Hope this helps.

     

    Best regards,

    Antoine



  • 4.  Re: Not able to pass password to powershell script

    Posted Sep 13, 2018 04:42 AM

    Dear Antonie,

     

    We are using agent version 10. So it is not possible to use :BEGIN_EXT_INT ... :END_EXT_INT tags.

     

    The below code is giving output like.

     

    :SET &LOGIN# = GET_LOGIN("LOGIN_TEST","*","win",PASSWORD)
    :print This is : &LOGIN#
    : SET &SecurePassword# = (&UC_JOBMD CMD="echo &LOGIN#")
    :print This is : &SecurePassword#

     

    Output :

    This is : 0000000000020482
    This is : N

     

    Thanks,

    Rajkumar Pandiaraja



  • 5.  Re: Not able to pass password to powershell script

    Posted Sep 13, 2018 09:35 AM

    Hi,

     

    this should work

     

    :SET &LOGIN# = GET_LOGIN("LOGIN_TEST","*","win",PASSWORD)
    :SET &URL# = "somepath"

    &UC_JOBMD CMD="echo &LOGIN#" > temp.txt
    set /p PASS=<temp.txt

    powershell -command D:\test\pstest\testing.ps1 -username "<ara_clnt>/<username>/<department>" -password %PASS% -artifacturl &URL# -profile "someprofile"


  • 6.  Re: Not able to pass password to powershell script

    Posted Sep 14, 2018 02:57 AM

    Dear Matthias,

     

    Thanks for your support.

     

    I have tried the given lines. But it is giving the same output. I guess &UC_JOBMD is not working properly.

    Please see the below line for the password.

    powershell -command D:\test\pstest\testing.ps1 -username "<ara_clnt>/<username>/<department>" -password
    0000000000020482 -artifacturl &URL# -profile "someprofile"


  • 7.  Re: Not able to pass password to powershell script

    Posted Sep 14, 2018 04:38 AM

    Hi,

    that is too little information for debugging. Please show us the script and the complete report.

     

    Regards, MS



  • 8.  Re: Not able to pass password to powershell script

    Posted Sep 14, 2018 06:26 AM

    Dear Matthias,

     

    Thanks for your reply.

     

    Please find the below job script which i have written.

     

    Windows Job :

    :SET &LOGIN# = GET_LOGIN("LOGIN_TEST","*","win",PASSWORD)
    :print This is : &LOGIN#
    : SET &SecurePassword# = (&UC_JOBMD CMD="echo &LOGIN#")
    :print This is : &SecurePassword#
    :SET &URL# = "somepath"

    &UC_JOBMD CMD="echo &LOGIN#" > temp.txt
    set /p PASS=<temp.txt

    powershell -command D:\test\pstest\testing.ps1 -username "<ara_clnt>/<username>/<department>" -password %PASS% -artifacturl &URL# -profile "someprofile"

     

    @set retcode=%errorlevel%
    @if NOT %ERRORLEVEL% == 0 goto :retcode

    Powershell Script:

    Param(
       [string]$ara_uri = "<ARA_login_page>",
       [string]$username = "",
       [SecureString]$password = "",
       [string]$artifacturl,
       [string]$profile
    )

    $body = @"
    {
      "workflow": "<ARA_Workflow>",
      "overrides": {
        "workflow": {
          "/artifactory/full-url": "$artifacturl",
          "/deployment/profile": "$profile"
        }
      }
    }
    "@;

       $pw = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))

    $params = @{uri = $ara_uri;
                       Method = "POST";
                       Body =  $body;
                       ContentType = "application/json";
                       Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($username):$($pw)"));
               }
       }
    invoke-webrequest @params

    Below is the job report with error message:

    C:\>C:\Automic\Agents\Windows\bin\UCXJWX6M.EXE CMD="echo 0000000000020482"  1>temp.txt  C:\>set /p PASS= 0<temp.txt  C:\>powershell -command D:\test\pstest\testing.ps1 -username "<ara_clnt>/<username>/<department>"
    -password 0000000000020482  -artifacturl &URL# -profile "someprofile"
    D:\test\pstest\testing.ps1 : Cannot process argument transformation on 
    parameter 'password'. Cannot convert the "20482" value of type "System.Int32" to type "System.Security.SecureString". At line:1 char:72 + D:\test\pstest\testing.ps1 -username <ara_clnt>/<username>/<department> -password 000000000 ... + ~~~~~~~~~ + CategoryInfo : InvalidData: (:) [testing.ps1], ParameterB indingArgumentTransformationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,testing.ps1


  • 9.  Re: Not able to pass password to powershell script

    Posted Sep 14, 2018 07:00 AM

    Ah okay,

     

    you have to fix your GET_LOGIN.

    :SET &LOGIN# = GET_LOGIN("LOGIN_TEST","*","win",PASSWORD)

     

    The value "0000000000020482" is the error code for "No entry found". A valid password starts with a double dash like '--2345235235DC324983248'.Try something like this:

    :SET &LOGIN# = GET_LOGIN("LOGIN_TEST",<hostname>,"*",PASSWORD)

     

    Replace <hostname> with a valid hostname.

     

    Matthias



  • 10.  Re: Not able to pass password to powershell script

    Posted Sep 18, 2018 02:23 AM

    Dear Matthias,

     

    Its working. But the problem is the password is visible in the job report. Any idea to avoid it?

     

    Thanks.



  • 11.  Re: Not able to pass password to powershell script

    Posted Sep 18, 2018 03:04 AM

    Hi,

     

    Yes, just add the @ sign at the beginning of every line with passwords, like this ...

    @powershell -command D:\test\pstest\testing.ps1 -username "<ara_clnt>/<username>/<department>" -password %PASS% -artifacturl &URL# -profile "someprofile"



  • 12.  Re: Not able to pass password to powershell script

    Posted Sep 25, 2018 08:12 AM

    Dear Matthias,

     

    It is working perfectly.

     

    Thanks for your support.



  • 13.  Re: Not able to pass password to powershell script

    Posted Sep 25, 2018 11:03 AM

    You're welcome