Set object color - Scripting - McNeel Forum
You probably need to use some python script, assuming one material per object. If you have too many object you will end up with a huge amount of materials in the file which may cause a problem.
I think you can use the script as a starting point,