Example 2 Find all positive integers $n$ such that $n=d(n)^{2}$.

Translate the above text into English, please keep the original text's line breaks and format, and output the translation result directly.
When $n=1$, the condition is satisfied. Below, we consider the case where $n>1$.
From the condition, we know that $n$ is a perfect square, so $d(n)$ is odd. Let $d(n)=2k+1$. For any positive integer $d$, when $d \mid n$, we have $\left.\frac{n}{d} \right\rvert\, n$. Therefore, by pairing $d$ with $\frac{n}{d}$, we know that $d(n)$ equals twice the number of divisors of $n$ among the numbers $1, 2, \cdots, 2k-1$ plus 1. Since the even numbers in $1, 2, \cdots, 2k-1$ are not divisors of $n\left(=(2k+1)^{2}\right)$, combining this with $d(n)=2k+1$, we know that every odd number in $1, 2, \cdots, 2k-1$ is a divisor of $n$.

Notice that, when $k>1$, $(2k-1, 2k+1) = (2k-1, 2) = 1$, so $2k-1 \nmid (2k+1)^{2}$. Therefore, when $k>1$, $n=(2k+1)^{2}$ does not meet the requirement, so $k=1$, and $n$ can only be 9.

Direct verification shows that 1 and 9 satisfy the condition, so $n=1$ or 9.