The invention discloses polyimide foam and a preparation method thereof. Aromatic dianhydride and/or aromatic acid ester, alcohol with low molecular, a catalyst and a surface active agent are mixed proportionally in a polar solvent and react so as to form foam precursor solution. The foam precursor solution and isocyanate react in a mould and freely foam into a foam intermediate. The intermediate is solidified by microwave radiation or/and oven heating to obtain solid polyimide foam. The preparation process has short path, simple technology, good stability for storage of the foam precursor solution, adaptation to processing technologies of pouring, spray coating, extrusion, and the like, no occurrence of defects of cracked foam, foam combination, subsidence and incomplete amination, low preparation cost as well as uniform hold diameter and stable performance of the solid polyimide form, and is convenient for popularization and application.