vendredi 12 novembre 2021

Powershell conditions for passed parameter

I am passing a hashtable that looks like that

$table = {
   Enabled = $true
   Name = $Name
}

I have a function which gets this object and creates an item. One of the Function's parameter is the Not Mandatory $Enabled status.

I want to create a condition that only in case the $Enabled parameter is passed to the function to accept it's content $true/$false. in other words, if I pass

$table={
  Name = $Name
}

it should create the object as a predefined value for Enabled - either true or false.

The condition

if($Enabled){
  do something
}

is executed either when the parameter is passed, or when it's set to true (which are desired scenarios). However, if it's set to $false (another desired scenario), it won't get into it. Thanks in advance

Aucun commentaire:

Enregistrer un commentaire