i have a function in a Powershell module which should establish a database session with SimplySql. SimplySql takes a credential object. Now i have several problems, to send the password into the function. What i tried:
When using a [string]$password parameter i get the warning
"Parameter '$password' should use SecureString, otherwise this will expose sensitive information"
. Makes absolute sense, so i changed the param to securestring.I created the secure string with
"$SecurePassword = "myPassword" | ConvertTo-SecureString -AsPlainText -Force"
, imported the module again and called the function. Now i get the following message:Cannot process argument transformation on parameter 'Password'. Cannot convert the "System.Security.SecureString" value of type "System.String" to type "System.Security.SecureString"
. I checked the SecureString with$myLocalSecString.GetType()
, and "yes" its a Secure String.Because i didn't found any solution for that, i tried to set
[PSCredential]$cred
as input object. I created the object with[pscredential]$_credObject = New-Object System.Management.Automation.PSCredential ("myusername", $SecurePassword)
. When i call the function now, i get the following message:
PowerShell credential request Enter your credentials. Password for user System.Management.Automation.PSCredential:
I think i created the SecureString on a wrong way in scenario 2 and 3, but i didn't what i doing wrong. The script should work on Powershell Core.
Would be great to get a good hint here.
Thanks in advance
Dave