If you run the script in Powershell ISE interface it works perfectly. If you schedule it it works perfectly. It should be good.