I am getting error when trying to bind argument to parameter ConvertTo-SecureString. Error refers to it as null.
CODE:
param (
[string]$NewPassword
)
$key = "ThisIsMyEncryptionKey1234"
$encryptedPassword = ConvertTo-SecureString $NewPassword -Key $key
Set-ADAccountPassword -Identity $env:USERNAME -NewPassword $encryptedPassword -Reset
$path = "n:\logs\pwtracker.txt"
$encryptedPassword | ConvertFrom-SecureString | Out-File $path -Append
This is the error I am getting:
ConvertTo-SecureString : Cannot bind parameter 'Key'. Cannot convert value "ThisIsMyEncryptionKey1234" to type "System.Byte". Error:
"Input string was not in a correct format."
At line:1 char:63
+ $encryptedPassword = ConvertTo-SecureString $NewPassword -Key $key
+ ~~~~
+ CategoryInfo : InvalidArgument: (:) [ConvertTo-SecureString], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ConvertToSecureStringCommand