There are 2 ways:

place the udf in your script (everywhere you like, most prefer the end of the script) or save the udf in a seperate file and call it from your script :

call '[path\]filename.udf'
_________________________