ConvertTo-SecureString turns a string into a System.Security.SecureString, the type that -Password and -Credential parameters expect. For plain text, add -AsPlainText and -Force:
$secure = ConvertTo-SecureString -String 'P@ssw0rd-Demo-2026' -AsPlainText -Force
In this tutorial, I’ll walk through ConvertTo-SecureString the way scripts actually use it: plain text, encrypted strings saved to a file, AES keys for other computers, and credential objects.
Every password here is a fake demo value. Use the same habit when you test, because whatever you type on the command line can end up in your history.
ConvertTo-SecureString syntax and parameter sets
The cmdlet has three parameter sets, and the one you pick decides how the input is read. This lists each set with its own parameters:
$common = [System.Management.Automation.PSCmdlet]::CommonParameters
(Get-Command -Name ConvertTo-SecureString).ParameterSets | ForEach-Object {
$names = $_.Parameters.Name | Where-Object { $_ -notin $common }
'{0,-10} {1}' -f $_.Name, ($names -join ', ')
}
Output:
Secure String, SecureKey
PlainText String, AsPlainText, Force
Open String, Key
Secure is the default and expects an encrypted string made by ConvertFrom-SecureString, optionally with -SecureKey. PlainText takes readable text, and Open takes an AES key as a byte array in -Key.
-String is positional and accepts pipeline input, so Get-Content file.txt | ConvertTo-SecureString works without naming it. The output is always one SecureString object, which you can confirm when you check the type of an object.
How do I convert plain text to a SecureString?
Pass the text to -String with -AsPlainText. Here’s the conversion, plus what PowerShell shows when you print the result:
$secure = ConvertTo-SecureString -String 'P@ssw0rd-Demo-2026' -AsPlainText -Force
$secure
"Type: $($secure.GetType().FullName)"
"Length: $($secure.Length) characters"
Output:
System.Security.SecureString
Type: System.Security.SecureString
Length: 18 characters
Printing a SecureString only shows its type name, never the value. Length is one of the few things you can read: 18 characters for the demo password.
The catch is the source. Microsoft warns that plain text in a script or on the command line can show up in event logs and command history logs. If you’ve done that with a real password, clear your PowerShell history.
Why -Force is required in Windows PowerShell 5.1
In Windows PowerShell 5.1, -Force confirms you understand that plain text can’t be protected. PowerShell 7 dropped that requirement but kept the parameter for compatibility. I ran the same script without -Force in both:
$version = "$($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor)"
try {
$secure = ConvertTo-SecureString -String 'NotARealPassword!' -AsPlainText -ErrorAction Stop
"PowerShell ${version}: converted $($secure.Length) characters without -Force"
}
catch {
$sentences = $_.Exception.Message -split '(?<=\.)\s'
"PowerShell ${version}: Failed. $($sentences[0])"
"Error ID: $($_.FullyQualifiedErrorId.Split(',')[0])"
}
Output:
PowerShell 7.6: converted 17 characters without -Force
The output above is from PowerShell 7, which converted the string. Windows PowerShell 5.1 refused with error ID ImportSecureString_ForceRequired:
