With increased penetration of renewable power and the nonlinear loads in the distributed generation (DG) systems, increased power quality concerns are exhibited, especially the challenges associated with the current and voltage harmonics in the system. Various conventional harmonic compensation techniques are developed for voltage-controlled DG inverters in past, majority involve either multiple proportional-integral (PI) or proportional-resonant (PR) controllers in eliminating grid current harmonics. The current-controlled inverters, on the other hand, are not preferred in industrial applications, accounting to their wide variations in the switching frequency. A novel and adaptive harmonic-voltage control is developed here, for voltagecontrolled DG inverters, which neither uses any PI regulators, nor imposes stability issues associated with non-ideal implementation of infinite gains of PR controllers. Interestingly, the developed control logic can be used for DG inverters, both in grid connected and off-grid operational modes. Furthermore, this strategy allows network operator to be used as an additional supplement that can be enabled/disabled as per the network requirement. The control logic exploits the property of optimal-switching-vector (OSV) controller i.e. accurate output voltage tracking. Simulations results demonstrate the effectiveness of the controller, to suppress grid current harmonics and load voltage harmonics in gridinterfaced and off-grid modes respectively, ultimately satisfying the mandatory IEEE standard-1547. Experimental results verify the viability of the controller for practical applications.