Unable to convert secure string back to plain text

Hi Everyone,

I am trying to display some data from a system that does not accept secure string for the password field. I am able to grab the username and password in plain text and log in but when I store the string as secure and try to convert it , it fails.

Failing:
Storing the Password:
$securekey = ConvertTo-SecureString -String ‘Password’ -AsPlainText -Force | ConvertFrom-SecureString
$Obj = New-Object -TypeName psobject
$Obj | Add-Member -MemberType NoteProperty -Name Username -Value ‘username’
$Obj | Add-Member -MemberType NoteProperty -Name Info -Value $securekey
$OBj | export-csv -Path C:\inetpub\wwwroot\test.csv -NoTypeInformation

Retrieving the Password:
$Cred = Import-Csv -Path C:\inetpub\wwwroot\test.csv
$Secure = $Cred.Info | ConvertTo-SecureString
$Unsecure = (New-Object PSCredential $Cred.Username,$Secure).GetNetworkCredential().Password
$Cred | Add-Member -MemberType NoteProperty -Name Password -Value $Unsecure

Error Message:

Successfully able to pull back:

$Obj = New-Object -TypeName psobject
$Obj | Add-Member -MemberType NoteProperty -Name Username -Value ‘username’
$Obj | Add-Member -MemberType NoteProperty -Name Info -Value ‘PlaintextPassword’
$OBj | export-csv -Path C:\inetpub\wwwroot\test.csv -NoTypeInformation

If you are using the enterprise version this has login pages. If you could provide a bit more of your script? As the issue might be a scoping issue…I can’t think off the top of my head how you trying to pull this off in a dashboard so a bit more code would help diagnose the situation if your password code works fine in ise

I am using the community edition right now. I might be able to get my company to spring for the Enterprise version if I can get this to work.

I am importing the credential manager module and using that to grad the credentials so they are stored securely. But that kept failing. I am trying to call the rightfax api to create a user. I’ll provide more scrubbed code soon. But I am using an elevated account to do this so users wouldn’t be able to do the functions now.

I did just post this on another question but have you read the Dude, where's my variable? Understanding scoping in Universal Dashboard
As my crystal ball is telling me that’s what you need to look into and https://docs.universaldashboard.io/endpoints/endpoint-initialization#passing-functions-to-endpoints
As I just have a gut feeling that’s what you need :smile:

1 Like

I will read through them both. I haven’t read the first linked document but I may have missed something in my first read of the second. I’ll let you know if I solve this by reading them!

Cool @TheFitITGuy I will have a think about how I could do this on a dashboard but from the error you posted and the gut feeling I got I think this will solve your issue. If I can assist further just give me a shout. But seriously man for $50 bucks I think it is for enterprise it’s an absolute bargain at this price…anyways as mentioned will think of authenticating on a dashboard if you not solved it let me know. Cheers

1 Like