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


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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You need to define it as a switch like this:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bart-VandyckAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.