I know in a lot of earlier wars people with no military experience were given officer commissions above the O1 rank. I was wondering if this ever happened in the bulk up of the military in the run up to WW1 or WW2 in order to fill out some of the middling officer ranks.
Officer's commissions were handed out above the O-1 grade for specific professions and occupations as the needs of the Army and Navy expanded. This was typically done for MOSs or jobs that required a certain level of seniority and expertise that that person already qualified for in their civilian field, and wouldn't necessarily be hard to translate when they carried out their specialty through military service.
So for example, it wasn't uncommon to see something like a civilian surgeon, engineer, or scholar being commissioned as an O-3 or O-4 depending on their specialty and experience in their respective fields. One example I like to point out, mostly because I studied a lot of the guys work for my thesis, is that of Samuel Eliot Morison.
Morison was a professional historian who focused on maritime history and taught at Harvard University prior to the beginning of World War II, whose most notable accomplishment prior to his entry was winning the Pulitzer for his book on Christopher Columbus, Admiral of the Ocean Sea. In May 1942, Morison met with FDR and offered to write a comprehensive history of U.S. Naval Operations during the war in exchange for getting insiders access and allowing Morison to gain a unique perspective of naval operations. Roosevelt agreed, and had Morison commissioned as a lieutenant commander (an O-4) in the navy. Morison then went on to publish the 15 volume History of the United States Naval Operations in World War II over the next twenty years. He eventually retired from the Navy as a rear admiral in 1951.
Source: Naval History & Heritage Command profile on Rear Admiral Samuel Eliot Morison