Not sure how to adjust this in PowerShell, but for the scheduled task, you need to choose "Run whether user is logged on or not", which will ask for credentials.