A strategy to eliminate harmonics from the grid current as the voltage of the point of common coupling (PCC) for microgrid applications is presented in this paper. The position of the harmonics reduction unit is selected so that it can reduce the harmonics level of the grid current and PCC voltage harmonics irrespective of the placements of the renewable energy sources in the microgrid. The proposed compensation system can be operated in both grid-connected and islanded operations of the microgrid system without changing any configuration. In the proposed control algorithm, the required amount of attenuation for harmonics is determined to meet the total harmonic distortion requirement specified by IEEE 519. Fast and efficient algorithm for phase detection irrespective of the presence of harmonics has been utilized for the system. The effectiveness of proposed method is verified by simulation and experimental results.