The process in which a relatively unspecialized cell acquires specialized features of a microglial cell. Microglia are glial cells that act as the immune cells of the central nervous system. They form part of the supporting structure of this system.