There are a variety of ways to track who was banned. None are really all that great for trying to do a simple unban script like you're asking for.

/help on ban

Using that, you can set variables (not very good, but it's easy), add it all into a hash table (better, but more difficult), store it to a file/ini (okay, but not that great), etc...

The hash table is perhaps the best method, but is harder to set up if you don't know anything about hash tables.

The easiest method would be to just get a listing of all bans in the channel and copy/paste the banmask with that unban command.