Let \(Z_{i,j}\) be the random variable defined by
\begin{equation*}
Z_{i,j}(\pi)=\begin{cases}1 \amp \text{if } \pi(i)\gt \pi(j) \\ 0 \amp \text{otherwise} \end{cases} \, .
\end{equation*}
Note that half of the permutations in \(\ss_n\) have an inversion at the positions \((i,j)\) (since for any ordering of the other \(n-2\) elements, there are two ways to order \(\pi(i)\) and \(\pi(j)\text{,}\) one with an inversion and one without). Using linearity of expectation, we thus have that
\begin{align*}
E[\inv] \amp = E\left[\sum_{1\leq i\lt j\leq n} Z_{i,j}\right] \\
\amp = \sum_{1\leq i\lt j\leq n} E[Z_{i,j}] \\
\amp = \sum_{1\leq i\lt j\leq n} \sum_{\pi\in \ss_n} P(\pi)Z_{i,j}(\pi) \\
\amp = \sum_{1\leq i\lt j\leq n} \sum_{\pi\in \ss_n: \pi(i)\gt \pi(j)} \frac{1}{n!}\cdot 1 \\
\amp = \sum_{1\leq i\lt j\leq n} \frac{n! / 2}{n!} \\
\amp = \binom{n}{2}\frac{1}{2} \, .\\
\amp = \frac{n(n-1)}{4} \, .
\end{align*}