Battery energy storage systems (BESSs) render different services in microgrids (MGs) depending on the MG connection mode. In the grid-connected mode, the BESS optimally injects/absorbs power, operated by a power converter controlled as the grid-feeding voltage source converter (GFD-VSC). In the islanded mode, the BESS may work as distributed slack bus controlled by the grid-forming VSC (GFM-VSC). However, for performing with a desirable performance, the GFD-VSC and the GFM-VSC demand different grid characteristics. Specifically, the GFD-VSC has a grid-synchronization issue and may become unstable in weak grids with high inductive impedance. Contrarily, the GFM-VSC reveals better performance when connected to the MG through a feeder with high inductive impedance. Besides, switching between different operating modes may cause undesirable transients. This issue can be addressed by the impedance shaping concept that is realized through the control design of the power converter. However, there is limited flexibility for impedance shaping using conventional PI-based controllers. To this end, in this paper, a universal controller is proposed, which is developed based on the impedance shaping concept. Also, sliding mode control (SMC) is used to overcome the undesirable transients due to switching between operating modes. The effectiveness of the control structure is evaluated in islanded operation, under weak grid connection, and FRT transients in MATLAB/Simulink.