With v4.5.x, there is no supported scripting feature. An API was introduced in v5.2 for this. If host names are not unique, you're going to have to go through them manually. Sorry for the bad news, I've had to do it too. I'm really looking forward to v5.2.