Skip to content

Latest commit

 

History

History
39 lines (26 loc) · 587 Bytes

Argument-Passing.md

File metadata and controls

39 lines (26 loc) · 587 Bytes

Argument passing

Now we have a function

function MyFunction ([string[]]$mylist, [string] $mystring) 
{
    Write-Host $mylist.Count
    Write-Host $mystring
}

This function will output the list, and then output my string.

And declare some variables:

$something = "something"

Call our function with null:

MyFunction($null, $something);

Guess the output?

Outputs:

2

Where is my 'something'? Where does the 2 comes out!?

What a strange behavior of PowerShell!

Repro env: Windows 10, PowerShell Core 7.0.3