I have an existing desktop app written in C# (I have the source code) that gets invoked from a script (currently batch script, but I will rewrite it as a PowerShell script) with a number of command-line arguments. I need to pass a password from the script to the app, and I am wondering how to do it in a more secure way. The best option to get password in PowerShell would be via the PSCredential object. Once PowerShell gets the password from the user, how can it pass it to the desktop app (and passing it in plain text via command line is not an option)?
I suspect one option would be to encrypt password in PowerShell and then decrypt it in C#, but I am wondering if there is a more elegant way to do this. If it matters, the script executes the desktop app in a loop with various parameters, but the same user credentials.