Required Parameter Name Missing - Works?

This topic contains 3 replies, has 4 voices, and was last updated by Profile photo of JasonMorgan JasonMorgan 3 years, 11 months ago.

  • Author
    Posts
  • #8558
    Profile photo of John_JHA
    John_JHA
    Participant

    I ran the following command and I didn't expect it to work because -LogName is positional (position 1) and I didn't specify the parameter name (-LogName). The command did run successfully. (And I wasn't prompted for LogName.)

    Why does the following command run properly?

    `Get-EventLog -EntryType "Information" System -Newest 5
    
    Index Time          EntryType   Source                 InstanceID Message
    ----- ----          ---------   ------                 ---------- -------
    3817 Jul 18 10:56  Information Microsoft-Windows...           19 Installation Successful: Wi
    3816 Jul 18 10:56  Information Microsoft-Windows...           17 Installation Ready: The fol
    3815 Jul 18 10:56  Information Microsoft-Windows...           17 Installation Ready: The fol
    3814 Jul 18 10:54  Information WMPNetworkSvc          1074607998 The description for Event I
    3813 Jul 18 10:54  Information WMPNetworkSvc          1074607998 The description for Event I`
  • #8577
    Profile photo of Bart Hoofd
    Bart Hoofd
    Participant

    As far as I know the first parameter you do not specify the parameter name for, will be considered the first [i]positional[/i] parameter. The same can be observed in examples like:

    
    Get-ChildItem -Recurse "C:\Windows"
    
    
  • #8579
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Whenever I run into one of these "WTF?!?" moments, I haul out Trace-Command. It can show me what's being bound where, and how. Would a tutorial be helpful? If so, I'll write one up for an upcoming TechLetter.

  • #8603
    Profile photo of JasonMorgan
    JasonMorgan
    Member

    I'd like to see an article on that.

You must be logged in to reply to this topic.