Link to home
Start Free TrialLog in
Avatar of Bart-Vandyck
Bart-Vandyck

asked on

Parameter as an option

Hi All,

I’m writing a small function, which lists some server names from a XML file.
While doing this it uses test-connection to check if the server is online or not.

This can be useful at times, it can take to long other times.

So I thought I make a parameter “-nc”  (no check) when I just need to have a list of available servers.

I made this small test script


param($nc)

Write-Host "arg1: $nc"

if ($nc)
{ "yep i see the nc"}


When I call it like this “testthis.ps1 –nc x” it works as expected

When I call it like this “testthis.ps1 –nc” it gives me the error that I need to supply an argument for the parameter.

So basically I want –nc to behave like on on/off switch (like –nonewline does for write-host) and not to behave like a parameter.

Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of rlandquist
rlandquist
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bart-Vandyck
Bart-Vandyck

ASKER

Perfect!!