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 PowerShell function:
function Return-True { return $true }
and then some sample code to invoke it:
PS C:\> Return-True True PS C:\> Return-True -eq $false True PS C:\> (Return-True) -eq $false False
Ideas? Comments?
When PowerShell sees the token
Return-Trueit identifies it as a command and until evaluation or end of the statement, everything else is an argument which is passed to the functionReturn-True.You can see this in action if you do:
That’s why all of the following return ‘True’, because all you are seeing is the result of calling
Return-Truewith various arguments:Using
(Return-True)forces PowerShell to evaluate the function (with no arguments).