Confinement of atoms inside impenetrable (hard) and penetrable (soft) cavity has been studied for nearly eight decades. However, a uniform virial theorem for such systems has not yet been found. Here we provide a general virial-like equation in terms of mean square and expectation values of potential and kinetic energy operators. It appears to be applicable in both free and confined situations. Apart from that, a pair of equations has been derived using time independent Schrödinger equation, that can be treated as a sufficient condition for a given stationary quantum state. Change of boundary condition does not affect these virial equations. In hard confining condition, the perturbing (confining potential) does not affect the expression; it merely shifts the boundary from infinity to a finite region. In soft case, on the contrary, the final expression includes contributions from perturbing term. These are demonstrated numerically for several representative enclosed systems like harmonic oscillator (1D, 3D), hydrogen atom. The applicability in manyelectron systems has been discussed. In essence, a virial equation has been derived for free and confined quantum systems, from simple arguments.