Multiple code formatting best practices, and some bug fixes combined #114
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi all,
I love the project, and would like to contribute to it.
When I started to look into the code I saw a lot of small formatting inconsequences, and a number of best practices for PowerShell Code are not followed.
This strikes me, as the script itself is meant to help us implement 'security best practices' so I'd recon the script itself then should also comply to PS Code best practices.
So I let the PSScriptAnalyzer run on the code, both for formatting, and best practices.
This led to the following changes. Most of them are minor formatting changes, but also 2 bugs were solved using the output from Script Analyzer
1 Removed trailing spaces using VSCode + Trailing Spaces addon
2 Updated Smart quotes “ and ” with straight quotes "
3 Updated codeformatting via PSScriptAnalyzer: Invoke-Formatter -ScriptDefinition (Get-Content .\Invoke-HardeningKitty.ps1 -Raw) -Settings CodeFormattingOTBS
4 Bugfix replaced = with -eq
5 Replaced Invoke-Expression with PS splatting to solve PSScriptAnalyzer warning regarding PSAvoidUsingInvokeExpression
6 Resolved all instances of PSAvoidUsingPositionalParameters by adding the parameter names.
BugFixed the call to Out-IniFile by removing the additional unused parameter
7 Switch types in Functions advanced parameters have a value of False set by default, and should not be set to false during declaration. Also bugfixed the .IsPresent usage (because being present doesn't mean it is true or false).
See https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters
Invoke-ScriptAnalyzer -Path .\Invoke-HardeningKitty.ps1
Now only gives a number of debatable warnings, we can look into them later.
I do realize lots and lots of lines are now updated with these updates. So I hope there are no other code changes pending, they'd cause large amounts of merge conflicts. But we can always discuss to re-do my changes at another time. most of the changes were automated and all can be re-done in an evening (as I just did ;-)
Regards, and hope this helps.
Note I DO have lots of PowerShell code experience, but hardly any 'GIT' experience, so if my propositions should be sent-in another way, that is totally fine with me.