A couple of questions about defaults (or lack thereof)

Welcome Forums General PowerShell Q&A A couple of questions about defaults (or lack thereof)

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
3 years, 6 months ago.

  • Author
    Posts
  • #26783

    Participant
    Points: 0
    Rank: Member

    I have a couple of questions about decisions which were made regarding defaults (or lack thereof).

    Anybody know why Format-Table doesn't default to -AutoSize? Everybody I know always uses this setting... unless they forget. Then they go "Doh!" and reissue the command with -AutoSize.

    The other decision that baffles me is why we need to add [cmdletbinding()] manually all the time. I can't recall a single script or function I've ever written where I didn't leverage this. Is there some reason for making it a manual addition?

  • #26784

    Keymaster
    Points: 1,785
    Helping HandTeam Member
    Rank: Community Hero

    AutoSize blocks the pipeline, which creates the perception of slower performance. Dunno if that's why, though.

    CmdletBinding was added in v2, I believe. It differentiates from older function types. Nowadays, I always use it also. But making it a default would break backward compat.

  • #26786

    Participant
    Points: 0
    Rank: Member

    Both legit reasons. Thanks.

  • #26801

    Participant
    Points: 151
    Rank: Participant

    Format-Table -AutoSize might be a good candidate for the $PSDefaultParameterValues preference variable. Here's a couple posts I wrote about it that will give your enough information to make -AutoSize the default: http://tommymaynard.com/?s=%24psdefaultparametervalues. Add this to your profiles, and it'll always be set.

The topic ‘A couple of questions about defaults (or lack thereof)’ is closed to new replies.