A string doesn't have a PowerState property, can you try that line as
while ((Get-VM $vmName).PowerState -eq "PoweredOn") {start-sleep -seconds 3}
A string doesn't have a PowerState property, can you try that line as
while ((Get-VM $vmName).PowerState -eq "PoweredOn") {start-sleep -seconds 3}