jeudi 3 mars 2016

Powershell: How can you determine which variable in an "if" statement triggered True?

In powershell, I have code that looks like this. The intention is to populate a handful of variables with data if a user doesn't supply any:

if ($1 -eq $null){$1 = "N/A"}
if ($2 -eq $null){$2 = "N/A"}
if ($3 -eq $null){$3 = "N/A"}

Is it possible to condense these down to something like this?

if ($1 -or $2 -or $3 -eq $null){
     $FILLER = "N/A"
}

Where $FILLER is the variable(s) that returned True?

Note: I don't have a problem with the individual if statements, I'm just aiming to condense repetitive code.

Aucun commentaire:

Enregistrer un commentaire