We have the recurrence relation $\displaystyle a_n = a_{n-1} + 2(n-1)$ for $n \geq 2$, with $a_1 = 2$.
Now I have to show that $\displaystyle a_n = n^2 - n +2$, with $n \geq 1$ using the generating function.
The theory in my book is scanty, so with the help of the internet I have the following:
$\displaystyle \sum_{n = 2} ^\infty (a_n - a_{n-1}) x^n = \sum_{n = 2} ^\infty a_n x^n - \sum_{n = 2} ^\infty a_{n-1} x^n = \sum_{n = 2} ^\infty a_n x^n - x \sum_{n = 2} ^\infty a_{n-1} x^{n-1} = (a(x) - a_1 x) - x(a(x)) = (a(x) - 2 x) - x(a(x)) = a(x) (1-x) - 2x$
But how I have to work out $\displaystyle \sum_{n = 2} ^\infty 2(n-1) x^n$ ?
If I have this, an expression for $a(x)$ can be found. How should $a_n$ be found from $a(x)$?
We have $a_n - a_{n-1} - 2n +2 = 0 \ (\star)$. Suppose the GF of $\langle a_n \rangle_{n\ge 1}$ is $f(x)$.
Then, $$\begin{align*} f(x) &= a_1 + &a_2 x& + a_3 x^2 + \cdots + a_n x^n + \cdots \\ -xf(x) &= &-a_1 x& - a_2 x^2 - \cdots - a_{n-1}x^n - \cdots\\ \frac{-2x}{(1-x)^2} &= &-2 x& - 4 x^2 \ \ - \cdots - 2n x^n + \cdots \\ \frac{2}{1-x} &= 2 + &2x& + 2x^2 \ \ + \cdots +2x^n + \cdots \end{align*}$$
Adding these up: $$f(x) -xf(x)-\frac{2x}{(1-x)^2} + \frac{2}{1-x} = (a_1 + 2) + \sum_{k=2}^\infty(a_k - a_{k-1} - 2k + 2)x^k.$$
But by $(\star)$, every term in the above infinite sum is $0$. Also our initial condition is $a_1 = 2$. So, $$f(x) (1-x) -\frac{2x}{(1-x)^2} + \frac{2}{1-x} = 4.$$
Solving for $f(x)$, we have $$f(x) = \frac{-4x^2+4x-2}{(x-1)^3} = \frac{-4x^2}{(x-1)^3} + \frac{4x}{(x-1)^3} - \frac{2}{(x-1)^3}.$$
The power series representation of $f(x)$ is then
$$f(x) = \sum_{n=0}^\infty \left( n^2-n+2 \right) x^n.$$
But the generating function for $\langle a_n \rangle$ was $f(x)$. So we can conclude that $$a_n = n^2 -n +2.$$
As you can see, using generating functions to solve recurrences is tedious, and requires a hefty amount of algebraic manipulation.