Powershell Switch Parameters No Values Required

The aim of this tutorial🔍 is the lesson needed for starting to use Powershell's functions with just -parameter without the provision of any value

1. steps

if($switchname) {activated}
  • you need to set a proper type [switch] before the argument
  • this works also in simple inline functions without the lengthy param block

2. example: query hashicorp consul

  • this is the local script I am using during operations to lookup a given value from within the HashiCorps Consul database
  • there are other things I am implementing: a short command-help, and argument typing
  • the prereq to using this is
  • âś…Consul installed
  • âś…Consul authenticated
>>> query-consul com_acme md5 -detailed

--

--

Infrastructure Support Engineer/Technical Writer (snowplow.io) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pavol Kutaj

Infrastructure Support Engineer/Technical Writer (snowplow.io) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com