[Solved] Input string was not in a correct format

When you want to convert a string to a secure string with ConvertTo-SecureString, you may get the
following error message

ConvertTo-SecureString : Input string was not in a correct format

Reason

This happens when you try to convert a regular string to a secure string.
“Convert To Secure String” string only means “to protect in memory”.

However, the standard input for the ConvertTo-SecureString cmdlet is an encrypted string.

Workaround

As a workaround you can use the AsPlainText parameter, which has to be associated with the Force
parameter (to confirm you understand the implications).

$MySecureString = ConvertTo-SecureString -String $MyPlainTextString -AsPlainText -Force

One thought on “[Solved] Input string was not in a correct format

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s