Need help in scripting

You are right.That happens automatically but we want to relocate the services before stopping the cluster so that if any issue is there while relocating it can be taken care of.
Moreover,when the node would be back up then the services won't fail back to the preferred instance hence for that also a script is required specific to a node services.

Best regards,
Vishal

So let me recap.

Case 1: You want to bring resources down for node maintenance, thus you want
to automate service relocation only if other instances, defined as "available", are actually available
and that/those service(s) is/are currently not active on other nodes.

Case 2: After bringing the node back online, you want to relocate back any service(s)
that have a preferred instance on that node.

Is that correct?

That's correct.

Best regards,
Vishal

OK,
that's not simple: there are too many variables. Let us know how it goes.