PnP
PnP

Reputation: 3185

Test-Connection Return Value

So Test-Connection with the -quiet switch can return a boolean. Now I need to somehow test to see whether that is True or False, then carry out an action dependent on that result. Is that possible? I'm fairly new to Powershell but I assume logic as follows:

If {Test-Connection -quiet PCNAME} == TRUE then..
Else... 

Any ideas?

Upvotes: 1

Views: 2556

Answers (1)

ash
ash

Reputation: 3474

the syntax is incorrect

if (Test-Connection -quiet PCNAME)
{
    # bla bla bla
}
else
{
    # bla bla bla
}

Also, powershell doesnt have an == operator, instead use -eq.

for example if ($foo -eq 0) { ... }

Similary:

-ne not equals

-gt greater than

-gte greater than or equal to

-lt less than

-lte less than or equal to

Upvotes: 5

Related Questions