This requires the Server Sided ID of the datablock. Server cannot tell the server that it is instantly using a brick. It is client sided.
well the first problem your going to run into is the /command requires a server-side addon -- unless you have a way around that.
but assuming you do...
just scanning all the object IDs is the wrong way to go about it.
the object IDs are assigned in the order things are created on the server (datablocks, clients, bricks, sounds, and such).
Since every server has a different set of addons, the sequence and order of the object IDs will be different for every server.
.... now im also wondering if there is a different or better way to accomplish what you are trying to do.
inside your script, and AFTER getting the brick datablock ID... what do you do? Specifically with the argument... what are you supposed to type? a name? a number? .. something else?