I’m typing this on a mobile device, so forgive typos and I can’t check syntax.
In addition to the limitations of actionscript not having loops, you need to understand that parameters are of type string and trying to set them with relevance that resolves to another type, or plurals of any type will fail. You then need to look at how strings are concatenated.
This would be a significant piece of work, but fortunately, forum search is your friend Unquoted Service Paths in Registry
The onus is still on you to check the PowerShell script to confirm it does what you want and expect.