Thanks for your response. I found this js API function in the forum. This is suitable for selective instance migration rather than bulk.
If you run in batch over 18000 instances, you will see session will be timed out.
A basic thumb rule, when you wanted to use JS API to execute a loop better not to touch more than beyond 200. Because it will eat up the server memory which leads to the hung threads.