Save security fom target DB before refreshing the database and put it in a sql job-step

I used to have a script that collected all the security I needed (last time I used it prob. w/ SQL v2008R2) it doesn't work now on v2016 plus now I need to add it to a 'refresh' job in a step within the job.

Any ideas?
I find a number of scripts that give me the before security but then I'd have to put it in temp tables on a miscellaneous database so I can execute the post refresh security, again with a job step.