If you are building PowerShell longer than a few lines, it is good practice to break up your code into reusable snippets. This way you can only call the code snippet over and over instead of ...
Now, the thing to remember is that we are using a CD4512 chip, whose truth table is shown below. The important thing to note here is that, in addition to the three multiplexer select controls, A, B, ...