Not a fire expert, but I did go ask a bunch of these questions before buying extinguishers for my workshop and I have put out quite a few electrical fires over the years on low and higher voltage equipment, so, here’s where I got to, very happy to be corrected by actual experts.
The foam and powder are both nasty and tend to leave you with a lot of cleanup or replacing things, however, if it’s already on fire you should ask the question of what is more important, putting it out quickly and reliably or trying to minimise extinguisher damage. There’s nothing that says you have to dump the whole extinguisher even after the fire has gone out.
I might be tempted to use an ‘electronics safe’ extinguisher for things like the VFD which might go woof, however, they tend to just let out magic smoke, unless they’re full of sawdust and have been enabled as a proper ignition source.
Water or foam on things with 110 / 230V I would want to knock out the power first. Low voltage stuff like the controller and steppers, you’ll probably kill the electronics, but, if it’s already on fire… If you’ve got a good EPO to drop power to the whole machine then that should assist in safety and damage to LV electronics.
Beware - on a VFD powering it off does not kill the internal voltage and depending on the fault mode there could still be 400V inside the VFD, I would not want to use a conductive extinguisher there, CO2, powder or blanket are good safer options there.
Fires on the machine are likely to be more easily handled and local than a fire in, or which propogates to, the dust collection system, which is likely to need higher volume extinguisher which is optimised for paper / wood type fires. Whether you have an enclosure has an impact here, if you open up with a CO2 extinguisher on a spindle / router fire in the chips on the workpiece you may just be distributing the fire, whereas if you have an enclosure you can fill the enclosure with CO2 (after shutting off extraction), close the doors and wait. - edit - the inside of your enclosure would want to be plain plywood or similar, not a light flammable foam or other coating which could cause rapid spread.
After lots of reading, pricing, being told that I needed a whole wall full of specialist fire extinguishers to allow me to choose the right one for the fire I’m currently experiencing etc. I ended up buying a couple of these
A small one and a 5kg for small fire and a ‘panic’ fire version. I accept they will make a nasty mess of whatever is on fire, but if it’s more than magic smoke from the electronics, I think I want the fire put out first and I’ll do damage assessment later. They claim it’s safe on electricals but there’s also an old kitchen fire blanket for the VFD if it goes woof, I try not to let it fill up with dust. The rest of the 230V power is all in a metal switchgear cabinet which can burn inside as much as it likes.
HTH