Concept: A list of some Best Practices for Windows PowerShell.


PowerShell Best Practice #1: Use full cmdlet name (not alias)

PowerShell Best Practice #2: Use named parameter (not positional and partial parameter)

PowerShell Best Practice #3: Avoid Write-Host

PowerShell Best Practice #4: Use CIM cmdlet (not WMI cmdlet)

PowerShell Best Practice #5: Avoid excessive and useless inline comments

PowerShell Best Practice #6: Use singular noun (not plural noun)

PowerShell Best Practice #7: Use approved verb (not unapproved verb)

PowerShell Best Practice #8: Use WhatIf and Confirm parameters

PowerShell Best Practice #9: Use custom folding regions

PowerShell Best Practice #10: Avoid empty Catch block

PowerShell Best Practice #11: Use Set-StrictMode

PowerShell Best Practice #12: Avoid Out-Null

PowerShell Best Practice #13: Avoid double quotes in strings if not necessary

PowerShell Best Practice #14: Specify the extension for applications

PowerShell Best Practice #15: Execute scripts with -NoProfile parameter

PowerShell Best Practice #16: Update the help

PowerShell Best Practice #17: Use the same parameter name than the native one

PowerShell Best Practice #18: Don’t use Notepad as a script editor

PowerShell Best Practice #19: Check parameters with PSBoundParameters

PowerShell Best Practice #20: Use full key name for calculated properties

PowerShell Best Practice #21: Use #Requires statement

PowerShell Best Practice #22: Use a parameter alias for backwards compatibility

PowerShell Best Practice #23: Avoid the horizontal scrolling (too long one-liners commands)

2 thoughts on “

  1. Thomas

    Hello
    Thanks a lot for this great Website!
    I’m pretty sure you don’t have an answer to this tricky question:
    If we call
    $obj | Select-Object
    then, Select-Object automatically detects the default printed properties for any object.

    How can we get the same list of all default printed properties for any PowerShell Object?

    Of course, we could save the output of Select-Object into a string and start parsing this string.
    But then, we’re again back in the scripting stone age 🙂

    Thanks a lot for any idea,
    kind regards,
    Thomas

    Reply
    1. Steve Renard Post author

      Hi Thomas,

      The question is not clear enough (maybe you refer to Format.ps1xml files to modify the output of an object). Can you give me a concrete example and let me know your PowerShell version?

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *