If you’re using a lot of functions in your script then writing them in C# can be a good way to simplify the logic as right now there’s much better tool support available for C# than PowerShell. You can do a lot more with your C# code than what I’ve shown here but hopefully it’ll be a good starting point for you!