In recent years, the harmonics and unbalance problems endanger the voltage and current quality of power systems, due to increasing usage of nonlinear and unbalanced loads. Use of Distributed Generation (DG)-interfacing inverters is proposed for voltage or current compensation. In this paper, a flexible control method is proposed to compensate voltage and current unbalance and harmonics using the distributed generation (DG)-interfacing inverters. This method is applicable to both grid-connected and islanded Microgrids (MGs). In the proposed method, not only the proper control of active and reactive powers can be achieved, but also there is flexibility in compensating the voltage or current quality problems at DG terminals or Points of Common Coupling (PCCs). This control strategy consists of active and reactive power controllers and a voltage/current quality-improvement block. The controller is designed in a stationary (αβ) frame. An extensive simulation study has been performed and the results demonstrate the effectiveness of the proposed control scheme. Depending on the compensation modes, the harmonics and unbalance compensation of DG output current, MG-injected current to the grid, as well as PCC and DG voltages, can be achieved in grid-connected operation of MG while in the islanded operation, and the PCC and DG voltages compensation can be obtained through the proposed control scheme.