Passing an optional parameter
<p>I have a PowerShell script <code>CSV2JSON.ps1</code> with the following code:</p>

<pre><code>param(
        [String]$FieldSeparator=",",
        [String[]]$Header
)

$input | ConvertFrom-Csv -Delimiter $FieldSeparator -Header $Header | ConvertTo-JSON
</code></pre>

<p>If I call it as <code>.\CSV2JSON.ps1 -FieldSeparator "|" -Header "name|age"</code> it works fine. However, if I drop the optional parameter <code>Header</code>, the <code>ConvertFrom-Csv</code> cmdlet complains that <code>Header</code> cannot be null:</p>

<pre><code>ConvertFrom-Csv : Cannot validate argument on parameter 'Header'.
The argument is null. Supply a non-null argument and try the command again.
</code></pre>

<p>I don't want to pass the <code>-Header</code> parameter at all, if it's not provided. Is there a neat way to pass on optional parameters without getting into <code>If</code> statements?</p>