Writing secure code
Most code has security flaws; it is our job to make sure that the code we write is as secure as possible. In this section, we will look at some ways to write more secure PowerShell code. We’ll look at how to store passwords our scripts might need, code signing scripts, and parameter validation.
Storing passwords securely
Quite often, we will write a script that contains commands that need to be run with a particular set of credentials. We saw how to store credentials in an XML file in Chapter 6, PowerShell and Files – Reading, Writing, and Manipulating Data. To recap, we can do it like this:
$cred = Get-Credential $cred | Export-Clixml Credential.xml
The credential is then stored in an XML object. This object contains an encrypted standard string, which is the password that was entered encrypted with a reversible encryption, based on the account and machine that the string was encrypted on. Let’s look at how this works.
I have...