Powershell Switch Parameters No Values Required

Pavol Kutaj
Mar 3, 2021

--

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

--

--

Pavol Kutaj

Today I Learnt | Infrastructure Support Engineer at snowplow.io with a passion for cloud infrastructure/terraform/python/docs. More at https://pavol.kutaj.com