Normally to enable the Broker Service, you need to simply use : "ENABLE_BROKER"
But when you restore the back up of database db1 to database db2, and after that if you want to enable broker service on database db2, then what to do? - That was my question.
The wording of the question and the code was misleading and confusing.
The code created one backup file db1.bak, and then restored from a differant file called main.bak. This means that it did not restore the backup created for db1 in the first script to to db2 in the second script. Your code restored a backup called main.bak. You quoted comment above does not apply since it assumes we all corrected a mistake in your questions code that was not apparent until after you had made responses here.
Did the database in the main.bak backup file have the Broker Service enabled when it was created?
Did you question make that fact clear?
It was completely unclear if any database had Broker Service enabled, disabled, or if it had ever been set-up when the backup file was created.
This could have been a really decent high level question had anyone taken time moment to read it and execute the code with it prior to posting.