![]() Taking this a step further we can save the secure string to a file that is then sourced in our script, here’s an example: Inspecting content of the $secureString variable after converting it with the ConvertFrom-SecureString we will see PowerShell create long string of random characters similar to this 1204890d04c9ddf0115d1….d3d491bb6d740864117a090d11, shortened for convenience, which is what internally PowerShell uses. ![]() ![]() ![]() Store Encrypted password in an external fileĪs seen in the previous example when creating a PSCredential object we need to specify a SecureString object as argument created with the ConvertTo-SecureString cmdlet. It is pretty obvious why this should never be used in production, anybody who has access to our code would be able to easily read username password which are conveniently written in the code. # Define Credentials $userName = 'admin' $userPassword = 'mySuperSecurePassword' # Crete credential Object $secureString = $userPassword | ConvertTo-SecureString -AsPlainText -Force $credentialObejct = New-Object -ArgumentList $userName, $secureString ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |