Forum Discussion

rubensfontes's avatar
rubensfontes
Copper Contributor
May 12, 2022

Get information from parameter store in JSON or in different lines

Hi everyone! 

I need some help. I have some user and password credentials in a parameter store. I need to retrieve this information to pass a credential to join a server in a domain. This retrieve can be to Json too.

At this moment Im using each value per line.
Example: 
myuser
myuserpassword

and using this to retrieve this values:


$username = (Get-SSMParameterValue -Name joinadwin -WithDecryption $True).Parameters[0].Value
$password = (Get-SSMParameterValue -Name joinadwin -WithDecryption $True).Parameters[1].Value
$credential = New-Object System.Management.Automation.PSCredential($username,$password)

In the step of a credential I receive this error:

New-Object : Exception calling ".ctor" with "2" argument(s): "Cannot process argument because the value of argument "password" is null. Change the value of argument "password" to a non-null value."

Using the Write-Host $password i saw the myuserpassword value 








  • rubensfontes 

     

    Hey, Rubens.

     

    I'm not quite sure what you mean by filter, but here's some quick illustrations on how to work with your JSON string.

     

     

    Cheers,

    Lain

  • rubensfontes's avatar
    rubensfontes
    Copper Contributor
    My username and password had a \ and I got escape error. I put one more \ on each one and it worked.

    Thank you everyone!
  • You need to convert it to a secure string, $credential=New-Object System.Management.Automation.PSCredential -Argumentlist @($Username,(ConvertTo-SecureString -String $Password -AsPlainText -Force))
  • rubensfontes's avatar
    rubensfontes
    Copper Contributor
    I can't filter values ​​in Json...

    {
    "username": "domain\teste",
    "password": "passsss"
    }
    • LainRobertson's avatar
      LainRobertson
      Silver Contributor

      rubensfontes 

       

      Hey, Rubens.

       

      I'm not quite sure what you mean by filter, but here's some quick illustrations on how to work with your JSON string.

       

       

      Cheers,

      Lain

Resources