You have a logical error in your program: $Par2 will always not be equal to $null or not equal to. ''
To fix the logic, you should use -and instead of -or here:
If ($Par2 -ne $Null -and $Par2 -ne '') { Write-Output "Par2 = $Par2" }
However, since you $Par2 argument $Par2 in the line in the argument list of the function:
Param ( [int]$Par1, [string]$Par2, [string]$Par3 ) ^^^^^^^^
checking for $Par2 -ne $Null not needed since $Par2 will always have a string of type (if you don't give it a value, it will be assigned. '' ). So you should write:
If ($Par2 -ne '') { Write-Output "Par2 = $Par2" }
Or, since '' evaluates to false, you can simply do:
If ($Par2) { Write-Output "Par2 = $Par2" }
source share