We extend the theory of the surface-induced magnetic anisotropy to mesoscopic samples with arbitrary geometry. The shape-induced anisotropy of impurity spins in small brick-shaped grains of dilute magnetic alloys is studied in detail. The surface-induced blocking of a magnetic-impurity spin is shown to be very sensitive to geometric parameters of a grain. This implies that the apparent discrepancy between the experimental data of different groups on the size dependence of the Kondo resistivity can result from different microstructure of the used samples. In order to interpret recent experimental data on the anomalous Hall effect in thin polycrystalline Fe doped Au films, we analyse the magnetisation of impurity spins as a function of the impurity position and of the grain shape.