[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

2 thoughts on “[Solved] Input string was not in a correct format

  1. omg, thank you. Spent over an hour banging my head trying to get this to work on a github workflow.

    Like

Leave a comment