I am trying to incorporate this function to my script but it shows me errors If I add any other code before this function as seen below. I enclosed the parameter in {} and the error no longer shows but it messes up my output since the parameters are no longer being defined. I have other code that needs to run and before this part of the script executes. You can see adding any other code before this function causes errors.
So I don't know how to include this part of the script with my other code and have it work. Any Help?

Get-TraceRoutecode and convert it into a function.