No UDF needed.

Simply modify the users logon script for each OU to run what script you want them to run.