Schedule task with PowerCLI script

For a past few hours I fought with task scheduler on Windows 2008 R2 and Vmware PowerCLI script to make it run as a service. I decided to write down quick guide to help out others and to document for myself.

Step 1 – Schedule task in Windows 2008 R2 scheduler.

  • create new task in Windows task scheduler
  • In General tab, Security option, specify user name under script will be executed and make sure that Run whether user is logged on or not is marked


  • In Triggers tab define conditions under scripts will get execute
  • in the action tab specify:
    • Action – start program
    • Program script – path to windows powershell – default path is:

    • Add arguments path to PowerCLI excution script vim.psc1 – default path is

  • Line should look like below:

  • When you apply changes and provide credentials information window pops up with below message


Step 2 – Add batch user to local security policy

  • In local security console –> User Right Assignment –> Log on as a batch job –> add a user which was specified in Step 1


Step 3 – Store user credentials to execute PowerCLI script in Windows scheduler.

Fortunately  vSphere PowerCLI gives possibility to export user credentials and store it in encrypted xml file. You can open the xml file, but the password is hashed.


[box type=”warning”] Make sure that one runs above script under user rights which script will be scheduled under. The reason is that by  default, only the user who has created the credential store file has rights to read it.[/box]

Artur Krzywdzinski

Artur is Consulting Architect at Nutanix. He has been using, designing and deploying VMware based solutions since 2005 and Microsoft since 2012. He specialize in designing and implementing private and hybrid cloud solution based on VMware and Microsoft software stacks, datacenter migrations and transformation, disaster avoidance. Artur holds VMware Certified Design Expert certification (VCDX #077).