Others beat me to posting the first two ways I thought of, so here's...
Another way:
ode = -(2y[x]/x^2) + 2 (1-1/x) y'[x]/x + (1-2/x) y''[x] == -1/x^7;
sol = DSolveValue[ode, y[x], x];
basis = D[sol, {Array[C, 2]}]; (* = {x-1, logs} *)
uode = ode /. y -> Function[x, basis[[2]] u[x] // Evaluate];
usol = DSolve[uode, u, x];
basis[[2]] u[x] /. First[usol] /. C[2] -> 0 //
Collect[#, C[1], Together] &
(*
(18 + 10 x + 5 x^2)/(576 x^4) + 1/4 (1 - x) C[1]
*)
Instead of lines 4 and 5 above, you can use the new function:
usol = DSolveChangeVariables[Inactive[DSolve][ode, y, x],
u, x, y[x] == basis[[2]] u[x]] // Activate
And another way:
C[2] -> Limit[C[2] /. First@Solve[sol == 0, C[2]], x -> 2]
sol /. % // Simplify // Collect[#, C[1], Together] &
(*
C[2] -> 5/192
(18 + 10 x + 5 x^2)/(576 x^4) + (-1 + x) C[1]
*)
And another way:
DeleteCases[Expand[sol /. x -> 1/2], t_ /; FreeQ[t, _Log]] //
Solve[# == 0] &
(*
{{C[2] -> 5/192}}
*)
And another way:
DSolveValue[{ode, y[2] == 0}, y[x], x]
DSolveValue[{ode,
y[2] == -Coefficient[%, x]/Coefficient[basis[[1]], x]}, y[x], x]
(*
(144 + 80 x + 40 x^2 + 29 x^4 - 29 x^5)/(4608 x^4)
(18 + 10 x + 5 x^2)/(576 x^4)
*)
And another way:
DSolveValue[{ode, y[2] == c}, y[x], {x, 0, 2}]
% /. First@
Solve[Coefficient[%,
x^Exponent[DeleteCases[Expand@%, t_ /; FreeQ[t, c]], x]] == 0,
c] // Simplify
(*
(144 + 80 x + 40 x^2 +
(29 - 4608 c) x^4 + (-29 + 4608 c) x^5)/(4608 x^4)
(18 + 10 x + 5 x^2)/(576 x^4)
*)
And another way:
The series solution has the following recurrence:
2 (1 + n)^2 a[1 + n] == (-1 + n) (2 + n) a[n]
By inspection, the constant term turns out to be free. If we set it to zero, all the higher-order terms vanish and we have a Laurent polynomial solution.
Subtract @@ ode /. y -> Function[x, Sum[a[k] x^k, {k, -4, 0, 1}]] //
CoefficientList[
Replace[Expand[#], {c_. x^k_ :> c*x[k], c_. x :> c*x[1],
c_ :> c*x[0]}, 1], Table[x[k], {k, -7, 2, 1}]] & // Flatten //
DeleteCases[0] //
Collect[#, Table[a[k], {k, -4, 0, 1}], Factor] & //
Sum[a[k] x^k, {k, -4, 0, 1}] /. First@Solve[# == 0] &
(*
1/(32 x^4) + 5/(288 x^3) + 5/(576 x^2)
*)
And another way:
Limit[sol/Log[2 - x], x -> 2] == 0 // Solve
(*
{{C[2] -> 5/192}}
*)
And another way:
x0 = Pi;(* any value in the domain of ode will do *)
yyp[x_ -> x0_] := NestList[D[#, x] &, #, 1] /. {x -> x0} &;
Thread[Array[C, 2] ->
LinearSolve[
yyp[x -> x0][basis],
yyp[x -> x0][(18 + 10 x + 5 x^2)/(576 x^4) - sol] /. _C -> 0]
]
(*
{C[1] -> 0, C[2] -> 5/192}
*)
And another way:
g = 1/(2 Pi) # Exp[I t]/4 /. {x -> 2 + Exp[I t]/4, _C -> 0} &;
Integrate[g@D[sol, x], {t, 0, 2 Pi}] +
C[2] Integrate[g@D[basis[[2]], x], {t, 0, 2 Pi}] //
Solve[# == 0] &
(*
{{C[2] -> 5/192}}
*)
And another way:
Related to the preceding method, but simpler.
Residue[D[sol, x], {x, 2}] == 0 // Solve
(*
{{C[2] -> 5/192}}
*)
Have fun. :)