To convert a string to a SecureString in PowerShell, use the ConvertTo-SecureString cmdlet. For a plain text string, pass the string and use the -AsPlainText and -Force parameters. For an encrypted string, pipe the encrypted data directly to ConvertTo-SecureString .. In this example, the ConvertTo-SecureString cmdlet takes the string "MyPassword123!" as input and converts it to a SecureString. The -AsPlainText parameter specifies that the input string is in plain text, and the -Force parameter overrides the security warning that would normally be displayed.. Once you run that command, PowerShell will encrypt the string into a SecureString.
Create a secure string from plain text, you should not actually do this because the string "P@ssW0rD!" is readable in the script:. Related PowerShell Cmdlets. ConvertFrom-SecureString - Convert a secure string into an encrypted standard string. Get-Credential - Get a security credential.. The ConvertFrom-SecureString cmdlet converts a secure string (System.Security.SecureString) into an encrypted standard string (System.String). Unlike a secure string, an encrypted standard string can be saved in a file for later use. The encrypted standard string can be converted back to its secure string format by using the ConvertTo-SecureString cmdlet. If an encryption key is specified by.