Create a CredentialEntry via Powershell fails

Create a CredentialEntry via Powershell fails

avatar

Good morning everybody,

in the past I used the following script to create a credential entry with user and password:

$pass=ConvertTo-SecureString -String $pass -AsPlainText -Force
$UserName="XXX"
$datasource = Get-RDMDataSource -Name "YYY"
Set-RDMCurrentDataSource -ID $datasource.ID
$Entry = New-RDMSession -Type Credential -Name $UserName -Group "ZZZ\ZZZ"
$Entry.Credentials.UserName = $UserName
$Entry.Credentials.Password
Set-RDMSession $Entry
Update-RDMUI
Set-RDMSessionPassword -ID $Entry.ID -Password $pass
Update-RDMUI

This was working fine, but now I get following error:

$Entry.Credentials.Password
InvalidOperation: Cannot get property value because "Password" is a write-only property.

I'm not sure what has changed, since the script is the same...

All Comments (1)

avatar

Hello,

Per the error you get and because the multiple entries RDM manages are having different object structures, it's no longer possible to assign any value directly to the Password property. We must use the Set-RDMSessionPassword cmdlet.

Here is your script updated with this method and please notice that we don't need to use the Update-RDMUI cmdlet after every new entry we create.

$pass=ConvertTo-SecureString -String $pass -AsPlainText -Force
$UserName="XXX"
$datasource = Get-RDMDataSource -Name "YYY"
Set-RDMCurrentDataSource -ID $datasource.ID
$Entry = New-RDMSession -Type Credential -Name $UserName -Group "ZZZ\ZZZ"
$Entry.Credentials.UserName = $UserName
Set-RDMSession $Entry
Set-RDMSessionPassword -ID $Entry.ID -Password $pass
Set-RDMSession $Entry -Refresh


Let us know if that works on your end.

Best regards,

Érica Poirier