Scalar-field cosmologies with a generalized harmonic potential and matter with energy density ρm, pressure pm, and barotropic equation of state (EoS) pm=(γ-1)ρm,γ∈[0,2] in Kantowski–Sachs (KS) and closed Friedmann–Lemaître–Robertson–Walker (FLRW) metrics are investigated. We use methods from non-linear dynamical systems theory and averaging theory considering a time-dependent perturbation function D. We define a regular dynamical system over a compact phase space, obtaining global results. That is, for KS metric the global late-time attractors of full and time-averaged systems are two anisotropic contracting solutions, which are non-flat locally rotationally symmetric (LRS) Kasner and Taub (flat LRS Kasner) for 0 ≤ γ≤ 2 , and flat FLRW matter-dominated universe if 0≤γ≤23. For closed FLRW metric late-time attractors of full and averaged systems are a flat matter-dominated FLRW universe for 0≤γ≤23 as in KS and Einstein–de Sitter solution for 0 ≤ γ< 1. Therefore, a time-averaged system determines future asymptotics of the full system. Also, oscillations entering the system through Klein–Gordon (KG) equation can be controlled and smoothed out when D goes monotonically to zero, and incidentally for the whole D-range for KS and closed FLRW (if 0 ≤ γ< 1) too. However, for γ≥ 1 closed FLRW solutions of the full system depart from the solutions of the averaged system as D is large. Our results are supported by numerical simulations.