Sort of the same....
If I wish to listen to online music I can either use my speakers or plug in a set of headphones. If I wish to use speakers when I listen to CD's then I must set the Audio Playback device to my speakers. To use headphones I must either change the audio Playback device to a different audio port or plug into the headphone port on the speaker.
If you use Program A and want Audio Device A to be used then the first option would normally be some default setting in Program A configuring/assigning the use of Audio Device A.
Likewise for Program B and Audio Device B. The assignment would be via the program default or configuration settings, if any, in the respective programs. E.g., headphones versus speakers. But that even requires that the default settings are configurable to the point that the headphones are on one audio output port (USB maybe) and that the speakers are on a different port; 3.5 mm (1/8").
Basically there has to be some logic that identifies the program being run in order to send audio output to the required/desired audio device/port.
Logic: Is Program A running? IF yes THEN use Audio Device A. Likewise for Program B, Program C, and so on. ELSE may help in situations where if Program A is not running then Program B would be running. ELSE Audio device B.
Powershell can handle some of the logic but I am not sure about how well, if at all, it would handle the necessary audio device assignments. Could require registry edits - very messy and risky. Could change with any program updates as well......
Setting Powershell aside:
Are you able to provide some specific details about your requirements? What programs, what audio devices, what connections, etc. are being used? That information will be helpful towards understanding the overall problem(s) which may lead to other possible suggestions and options.