I am seeing some rather weird behavior with PowerShell, it looks like custom functions might need a \"parenthesis wrapper\" to evaluate as you might expect them. Given a simple
When PowerShell sees the token Return-True
it identifies it as a command and until evaluation or end of the statement, everything else is an argument which is passed to the function Return-True
.
You can see this in action if you do:
PS > function Return-True { "The arguments are: $args"; return $true }
PS > Return-True -eq $false
The arguments are: -eq False
True
That's why all of the following return 'True', because all you are seeing is the result of calling Return-True
with various arguments:
PS > Return-True -eq $false
True
PS > Return-True -ne $false
True
PS > Return-True -eq $true
True
PS > Return-True -ne $true
True
Using (Return-True)
forces PowerShell to evaluate the function (with no arguments).