  We obtain a family of exact solutions describing magnetized black holes in an
external gravitational field. Locally the solutions can be interpreted as
representing the near-horizon region of a black hole, which interacts with a
surrounding matter distribution producing a strong magnetic field. Thus, the
solutions reflect the influence of both a gravitational and an electromagnetic
external potential in the strong field regime. The static members in the family
are generalizations of the Schwarzschild solution in the described environment,
while the rotating ones generalize the magnetized Reissner-Nordstr\"om solution
when the influence of an external gravitational source is also taken into
account. Technically, the solutions are obtained by means of a Harrison
transformation. We examine the thermodynamical properties of the solutions, and
compare them with the corresponding isolated black holes, and with the
particular cases when the interaction with only one of the external potentials
is taken into account. For the static black holes the influence of the external
gravitational and magnetic fields is factorized in a sense, both affecting
different properties, and leaving the rest intact. For the rotating solutions
the external gravitational and magnetic fields are coupled through the
conditions for avoiding conical singularities. The Meissner effect is observed
for extremal rotating solutions only in the zero-charge limit, similar to the
magnetized Reissner-Nordstr\"om black hole.
