Hi,
I'm working for over 15 years in IT and have vast experience with scripting.
I guess you want to run this script prior a new Office installation, so I would recommend running it as a startup script via GPO.
Happy to help and have a chat about the details.
Regards,
Sebastian