Determining if n is a square from number of divisors?

I've noticed for a few cases that if you compute all the divisors of a composite number, if this list of divisors (including 1 and the number) is even, then the number is not a square, and if it's odd, it is a square.

But that's just for some specific examples like

divisors of 30 : {1, 2, 3, 5, 6, 10, 15, 30 } : even # of divisors, and not a square

divisors of 36: {1, 2, 3, 4, 6, 9, 12, 18, 36}: odd # of divisors, and is a square.

I'm wondering is this just a coincidence, or does this hold for all numbers? And are there any correlations between number of divisors and if the number is a cube, a quadruple, etc?