Tyler Dickson Tyler Dickson - 11 months ago 122
PowerShell Question

Greater-than PowerShell operator giving inaccurate results

For some reason, when I debug -

is equal to 1, yet when the debugger hits
if(numUsers -gt 2)
, it enters the if block...

function numUsers()
{@(query user /server:$server).Count - 1

$debug = numUsers

if(numUsers -gt 2)

Am I using the -gt operator properly? Am I missing something really obvious?

Appreciate any insight


The -gt 2 are being seen as arguments to the numUsers call as written.

You can see that by looking at the value of $args in your numUsers function.

You need to tell powershell that you want to call numUsers on its own for this to work.

if ($(numUsers) -gt 2) {
    "gt 2"
} else {
    "lt 2"