Do you use configuration files for PowerShell scripts?
Updated by Tiago Araújo [SSW] 3 years ago. See history
Import-PowerShellDataFile.
Some of the things we can do in a PSD1 file:
- We can write comments;
- We can use lots of data types, like int, float, bool, string, array...
- We don't need to use quotes around field names like JSON;
- And more.
Instead of keeping all your important URLs and FQDNs inside your PowerShell script, you should keep the script itself clean and "sanitized" from those hard-coded variables, so it can be freely shared on GitHub without any security concerns for you or your company. It also makes the script much more maintainable, where you can easily change the variables in the .PSD1 file without needing to change your core script. Don't forget to add the configuration file to .gitignore!

❌ Figure: Bad Example - Your script variables are in the script itself, making it insecure to share outside
Credits to: PowerShell Accidentally Created A Nice Configuration Format.
Categories
Need help?
SSW Consulting has over 30 years of experience developing awesome software solutions.