Get-WebAppPoolState does not return a string, but an object of type CodeProperty. You will need the Value property from this object, that is:
$state = (Get-WebAppPoolState AppPoolName).Value;
I assume that some kind of converter displays the first case when it is written to the output, therefore Stopped is displayed, but not for writing to the hosting, so instead you get the default representation of the object (which is the type name).
source share