Hi TS
Welcome to Q&A Forum, this is a great place to get support, answers and tips.
Thank you for posting your query, I'll be more than glad to help you out.
As I understood, you want to run that script on a regular basis to rebuild all indexes of a given database, and you want to use the Windows Task Scheduler for that...
Then you have to store that script as a *.sql file, write a PowerShell script which connects to your database and executes that sql-script (for example with commands from the module "dbatools"), then you create a task in task scheduler to trigger/run that PowerShell script every week (eg).
https://docs.dbatools.io/Invoke-DbaQuery.html
https://voiceofthedba.com/2015/12/09/running-powershell-with-task-scheduler/
Or a different approach would be using Azure Automation to run that *.sql script as explained in this blog post:
https://geeks.ms/davidjrh/2015/10/08/rebuilding-sql-database-indexes-using-azure-automation/
but this post is already some kind of old and there where a lot of changes in the portal, so maybe service names had been changed and the design of the portal will look different. but the blog post and the explanation should lead you into the right direction.
I hope my answer is helpful to you,
Your
Bjoern Peters
If the reply was helpful, please upvote and/or accept it as an answer, as this helps others in the community with similar questions. Thanks!