0

I created a scheduled task to shuwdown/deallocate itself (it's a VM on Azure) with Powershell.

The PowerShell script is: Stop-AzureVM -Name "myvm" -ServiceName "myservice" -Force

If the PowerShell is ran by the scheduled task, the task just keeps on running and never shuts anything down.

What am I doing wrong? The user that executes the task is local admin on the VM itself. I tried to wait until the trigger to fire (after a specific time) and also tried to run it on demand (right click => run now), but none of them worked.

But if I right click on that same PowerShell script file and "Run with PowerShell", then it works like it should.

  • How are you calling the script within task manager? Can you show the Program/script and Arguments from the Actions tab for the task? – Tim Ferrill Jun 5 '14 at 14:12
  • @TimFerrill, it says "Start a program" and then points to the path of the PowerShell script file. – Ray Cheng Jun 5 '14 at 15:28
1

Ensure the task is configured with the path of the PowerShell.exe file in the Program/script value of the task action:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

And reference the script using the -File parameter in the arguments value:

-File "C:\Scripts\myScript.ps1"
0

I have gone through the same challenge for scheduling my VMs to start/stop at a scheduled time using window task scheduler.I was going through the same approach and script. After spending more than 3 days I came to know this is not possible by this method. It will show process status as completed in task scheduler but it will not actually do its task. So, Better you use the azure management portal and use automation runbooks for the same. This one worked for me. Just keep in mind that you need to provide credentials before setting up the runbooks for the same.

You can use the following refrences-

http://azure.microsoft.com/blog/2014/11/25/introducing-the-azure-automation-script-converter/ http://azure.microsoft.com/en-us/documentation/articles/automation-create-runbook-from-samples/

Hope this will help you. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.