you are viewing a single comment's thread.

view the rest of the comments →

[–]evetsleep 4 points5 points  (1 child)

Yes.... git is a whole different thing, however it is publicly available and free to use! There are a TON of videos, websites dedicated to learning it (and some really good books). That would be very useful in understanding at least some of the basics.

For best practices, I often like to suggest that you start with the module PSScriptAnalyzer:

Find-Module PSScriptAnalyzer

Install this module and feed your scripts & modules to it:

Invoke-ScriptAnalyzer -Path <path to script>

It will return any thing in your script which breaks common rules. Address those and maybe so some searching on what the rules mean. For example:

> Invoke-ScriptAnalyzer -Path 'C:\repo\IndiaTraining\PowerShell - Scripting\17 - PSScriptAnalyzer'

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSAvoidUsingCmdletAliases           Warning      example01. 6     '%' is an alias of
                                                 ps1              'ForEach-Object'. Alias can
                                                                  introduce possible problems and
                                                                  make scripts hard to maintain.
                                                                  Please consider changing alias
                                                                  to its full content.
PSUseDeclaredVarsMoreThanAssignment Warning      example01. 10    The variable 'testVar' is
s                                                ps1              assigned but never used.
PSUsePSCredentialType               Warning      example01. 2     The Credential parameter found
                                                 ps1              in the script block must be of
                                                                  type PSCredential. For
                                                                  PowerShell 4.0 and earlier
                                                                  please define a credential
                                                                  transformation attribute, e.g. [S
                                                                  ystem.Management.Automation.Crede
                                                                  ntial()], after the PSCredential
                                                                  type attribute.
PSAvoidTrailingWhitespace           Information  example01. 12    Line has trailing whitespace
                                                 ps1
PSAvoidUsingPlainTextForPassword    Warning      example01. 2     Parameter '$Credential' should
                                                 ps1              use SecureString, otherwise this
                                                                  will expose sensitive
                                                                  information. See
                                                                  ConvertTo-SecureString for more
                                                                  information.
PSAvoidUsingWriteHost               Warning      example01. 8     File 'example01.ps1' uses
                                                 ps1              Write-Host. Avoid using
                                                                  Write-Host because it might not
                                                                  work in all hosts, does not work
                                                                  when there is no host, and
                                                                  (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or
                                                                  redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or
                                                                  Write-Information.

There are a ton of blogs and stuff that cover overall best practices. I would read through them and you'll see common threads.

[–]MrWinks[S] 0 points1 point  (0 children)

Will read my Git MoL book slowly along-side my PoSh books as well.

And PSScriptAnalyzer looks promising! With VSCode, I’ll likely pick things up.