One material, different colors on objects
You can use the Pass Index to discriminate between objects with the same material.


In Object Properties > Relations, assign a Pass index to each object, between 1 and [ your number of distinct colors ]. You can assign the index to multiple selected objects by right-clicking the Pass Index field on the active object, and choosing 'Copy to Selected'.
Replace the RGB node in your tree with the nodes illustrated here:




The Divide is just to map the range of integers to 0.0 .. 1.0 for the color ramp, and the subtract nudges the point to make the tabs in the color ramp easier to place)



If you need the Pass index for something else, you can drive a Value node from a Custom Property, but that's not quite so convenient to assign.