2

Using Powershell I'd like to call my script as follows:

myscript.ps1 -device1 enable -device2 disable -device3 enable

Each device paramenter is defined as String followed by a bool value.

param(
  [string] $device1,
  [string] $device2,
  [string] $device3
)

Does PowerShell support this with some predefined functions or parameters or would you implement this in a totally different way? I'd like to avoid a parsing for enable and disable.

1 Answer 1

4

I would implement this using a switch:

param(
  [switch] $device1,
  [switch] $device2,
  [switch] $device3
)

So you can invoke your script using:

myscript.ps1 -device1 -device3
Sign up to request clarification or add additional context in comments.

3 Comments

This would mean that e.g. device2 will be set to false if not set when calling the script?
exactly. If you want, you could also specify this using -device2:$false but you don't have to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.