Parameter Name should be in Upper Case

This topic contains 3 replies, has 4 voices, and was last updated by Profile photo of Ron Ron 1 month ago.

  • Author
    Posts
  • #56963
    Profile photo of Roy Hadley
    Roy Hadley
    Participant

    Is this possible.
    I have created a custom function called New-File

    Function New-File {
    param($Path,$Name)
    New-Item -Name $Name -Path $Path -ItemType File
    }

    If the Parameter Path or Name is type by the user in lower case, it should not work.

    This should work
    New-File -Path E:\ -Name Testing

    This should not work. As the path parameter is type in lower case.
    New-File -path E:\ -Name Testing

    I tried using $PSBoundParameters but failed. Is there a way to do this.

    Reason: My Client want it this way.

  • #56965
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    PowerShell is by design case insensitive so I doubt this is possible. case sensitivity for parameters doesn't make any sense

    • #56968
      Profile photo of Olaf Soyk
      Olaf Soyk
      Participant

      So you might ask your client what's the advantage of having case sensitive parameter names. IMHO that's the most futile request I have ever heard of.

  • #57037
    Profile photo of Ron
    Ron
    Participant

    The only way you'll likely accomplish this is to do your own argument processing.

    function test_args()
    {
      Write-Host "arg 0:  $($args[0])"
      Write-Host "arg 1:  $($args[1])"
    }
    
    test_args -File "Name"

You must be logged in to reply to this topic.