Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

With functions

  function Get-Something {
    Param (
      [Parameter(Mandatory=$true, Position=0)]
      [string] $Name,
      [Parameter(Mandatory=$true, Position=1)]
      [int] $Id
    )
    # Write the output to the console
    Write-Output "Name: $Name, Id: $Id"
  }

  Get-Something "Alice" 42
If you were to call

  Get-Something("Alice", 42)
It would pass "Alice", 42 to the first parameter.

You can use named parameters to get round this, e.g.

  Get-Something -Name "Alice" -Id 42
Still a bit of a gotcha!


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: