Disclamer

Visit our disclaimer policy before making any changes to your system which may negatively impact the performance or make your system unresponsive.

Scheduling Task in Windows

Using Task Scheduler in to run scripts.

Table of Contents

Giving User Logon as Batch Permission

Suppose the user account running the task is not a administrator account or has not been assigned the Log on as batch permission. The below error may be thrown when creating the job.

The following steps will add an account to the Log on as batch security group on a Windows Server. YOU MUST HAVE ADMINISTRATIVE PRIVILEGES ON THE MACHINE TO DO THIS TASK.

  1. Open up Local Security policy by
    1. Typing Local Security Policy in the search bar; or,
    2. Start button -> scroll down and locate the Windows Administrative Tools folder, and select Local Security Policy; or,
    3. From run, command line, or PowerShell, type secpol.msc
  2. Expand Local Policies -> User Right Assignments -> find Log on as batch job and open it up.
  3. Click the button Add User or Group… -> locate the user and hit the OK button.

The user account will now be able to run a task from Task Scheduler.

Creating a Task

  1. Open up Task Scheduler by
    1. Typing Task Scheduler in the search bar; or,
    2. Start button -> scroll down, locate the Windows Administrative Tools folder, and select Task Scheduler; or,
    3. From run, command line, or PowerShell, type taskschd.msc
  2. Right-click Task Scheduler Library -> Create Task…
  3. In the following tabs
    1. General Tab
      1. Give the task a Name: and a detailed Description
      2. In the Security options section
        1. Click the button Change User…
          1. If the server is not part of a domain, enter the local user account to run the script.
          2. If the server is part of a domain, hit the Locations… button and select either the Domain the account is in, Entire Directory, or the OU the account is in and hit the OK button
          3. Perform a search for the user account.
            1. Hit the OK button
  1.  

IT IS NOT RECOMMENDED TO USE A ACCOUNT THAT IS ALREADY BEING USED FOR OTHER FUNCTIONS. IT IS BEST TO USE A SERVICE ACCOUNT FOR RUNNING TASKS. If you need to create a service account, click the link here.

      1. Hit the bubble for Run whether user is logged on or not
    1. Trigger Tab
      1. Hit the New… button
      2. Select the applicable option that you need for your task to run. In this run-through, we will use the: On a schedule option.
      3. Settings
        1. In the following window, select your Date and Start Time. Depending on the option chosen, there might be a Recur every: or Months: Days: and On: options, etc.
        2. In Advanced settings
        3. Set any advanced settings
      4. Hit the OK button
    2. Actions Tab
      1. Hit the New… button
        1. Settings Section
          1. To run a PowerShell Script
            1. Program/script:
              1. To use by name, in the box, enter: PowerShell
              2. To use by direct path, in the box, enter: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
            2. Add arguments (optional): Add the option –File with the path in quotation marks to the PowerShell script.
      1. Once done, hit the OK button three times to close out all the windows.
  1. Enter the password for the User Account that we entered in select user box.
  2. Hit the OK button

If the below error message pops up, the selected account is not configured to run as a batch user. Please see the top section on how to give access.

Migrating Azure AD Connect

Don’t waste time figuring out how to migrate Azure Active Directory from one server to another. Do it quick and don’t waste your time and get it done within an hour.

Read More »

Contact Us