Im trying to make a rudimentary credential store for some service accounts on a web app. I have a web page that I put in the username and password and it POSTs to the code below
Param
(
[Parameter(Mandatory = $true)] $Username,
[Parameter(Mandatory = $true)] $Password
)
$secpwd = $Password | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString
$newline = "$($Username),$($secpwd)"
$newline | Add-Content "..\Database\accounts.csv"
For whatever reason what I get is username,blank in the csv and Im not entirely sure why. I did rewrite this locally using params gathered from the command line and that test works. In an earlier interation of this code it would actually return the plain text password.
EDIT: Im adding the output of a try/catch: ConvertFrom-SecureString : The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.