Thought Experiment Help Requested

I have the beginning of a function that I want to use, but I need help simplifying the following scenarios (SQL related).

My goal = write the leanest function logic possible to accommodate the use cases described below.

I call the function and with an Instance. = 1,0

I call the function without an instance. = 0,0

I call the function with an instance, but without a DB. = 1,0

I call the function with an instance, and a DB. = 1,1

I call the function without an instance, but with a DB. = 0,1

I call the function with a DB. = 0,1

For some reason I am hung up on simplifying these use cases, despite the fact I wrote it out in a binary/true false type story.

I am stuck picturing a variable associated with some sort of a switch statement instead of nested if(s).



A colleague and I discussed this and I am currently onboard with something like the following:

Switch Variable - maybe an int

Case 1 Call with instance

Case 2 Call w/out instance, but with DB

Case 3 Call with instance with DB

Case 4 Call w/out instance, and w/out DB

Default = Case 4

What would it be doing when you say call the function with Instance/DB etc ?
It can be simplified depend up on the variations in action.

Fantastic point the simplest example looks something like this

test-sqlcred -instance "SQL01" -database "default1" -credential $cred

#Essentially if you enter a single string then we do this Get-SqlDatabase -Credential $cred -name $database -serverInstance $instance

#Leaving the instance option blank I use get-adcomputer and registry queries to populate a list of computers with instances to check