Thursday, May 24, 2012

Convert a String Variable to a Secure String

When you are working with cmdlets that want passwords, the cmdlets require the password to be a secure string rather than a regular string. A secure string is encrypted in memory. When you read data from a csv file, it is automatically imported as a regular. To read a password from a file and use it, you need to convert it to a secure string.

To convert an existing string to a secure string use the following:
$SecurePass = ConvertTo-SecureString $UnsecurePass -AsPlainText -Force

After converting to a secure string, you can use it as a password when create user accounts with New-ADUser or as part of credentials you are passing to a cmdlet.

For more information about working with passwords, secure strings, and credentials see the following TechNet article:

No comments:

Post a Comment