Giter Club home page Giter Club logo

scheduledscripts's Introduction

TL;DR

  1. Write your PowerShell script
  2. Drop it in C:\ProgramData\Scheduled Scripts\Tasks\Daily
  3. Watch mom, it runs every day!

Windows Scheduled Script

Linux users are familiar with cron - a daemon that launches programs and scripts at predefined intervals. Likewise, Windows has a more full-featured (and complicated) service called Task Scheduler. It comes with almost all editions of Windows, both client and server.

Task Scheduler has lots of advanced features, but sometimes we just want to do something simple, like running something daily, weekly, on computer startup, etc. For that, the Linux world has a clever solution - just drop your scripts in a hardcoded path (/etc/cron/monthly, /etc/cron/daily, etc.) and it's done!

This project aims to let you do just that, on Windows!

Install

Unzip the installation archive to your local drive (e.g. %temp%).

Run Powershell with administrative privileges (WIN+x > Windows PowerShell (Admin)). Make sure your system can execute script:

Get-ExecutionPolicy

If not 'Unrestricted' (you can change it back later):

Set-ExecutionPolicy Unrestricted

Then:

. .\install.ps1

This script does 3 things:

  1. Copy out the contents of the src under it to %ProgramData%\Scheduled Scripts.

  2. Create 2 logs: Host Access and Scheduled Scripts. You can see them by running compmgmt.msc (Event Viewer > Applications and Services).

  3. Create various scheduled tasks. See the System Scripts folder in the Task Scheduler (run taskschd.msc with administrative privileges).

Using Windows Scheduled Script

Simply copy your script to one of the appropriate folders in %programdata%\Scheduled Scripts\Tasks.

  • Daily: Runs all scripts under %PROGRAMDATA%\Scheduled Scripts\Tasks\Daily\*.ps1 every day from about 3:00PM to 3:30PM. All scripts will execute with the "NT AUTHORITY\NETWORKSERVICE" privileges. No user needs to be logged on.

  • Monthly: Runs all scripts under %PROGRAMDATA%\Scheduled Scripts\Tasks\Monthly\*.ps1 on the first day of every month from about 5:00PM to 5:30PM. All scripts will execute with the "NT AUTHORITY\NETWORKSERVICE" privileges. No user needs to be logged on.

  • Weekly: Runs all scripts under %PROGRAMDATA%\Scheduled Scripts\Tasks\Weekly\*.ps1 every Monday from about 4:00PM to 4:30PM. All scripts will execute with the "NT AUTHORITY\NETWORKSERVICE" privileges. No user needs to be logged on.

The above will not run if the system is running on battery. Their 'battery exempted' versions are exactly the same, but will run even if the PC is running on batteries.

  • Startup: Runs all scripts under %PROGRAMDATA%\Scheduled Scripts\Tasks\Startup\*.ps1 every time this computer starts up with the current operating system. No user needs to be logged on. This task will run on both battery and AC power.

All tasks will not execute again until the next scheduled time if it missed its scheduled start for any reason.

Security Matters

Scripts are protected by NTFS filesystem security itself. The access control for %PROGRAMDATA%\Scheduled Scripts is designed to require administrative privileges for write operation, thus preventing a malicious program from making changes to your script folder.

PowerShell execution policy is not used, because it is very trivial to get around its restriction.

Sample Scripts

Here are the ones that comes with this package:

Tasks/Startup/MountVHD

Automatically mount VHD to your preferred drive letter on PC start up. YOU MUST EDIT Configuration\MountVHD.json for it to work.

{
    "logLevel": "Information",
    "vhdBasePath": "C:\\ProgramData\\Blobs",
    "vhd": {
        "Profile": {
            "driveLetter": "E",
            "ensure": true
        }
    }
}

The above will mount C:\ProgramData\Blobs\Profile.vhdx to E: on computer start up. The ensure flag means failing the script if E: is occupied. Set to false to use the next available drive letter.

You can omit vhdBasePath. It defaults to %ProgramData%\Blobs.

Valid values for logLevel: Error, Warning, Information, Verbose. Defaults to 'Information'.

Tasks/Daily/GetBingWallpaper

Download wallpapers off Bing.

This task does not need a configuration file to run, but you can customize it by creating a file under Configuration\GetBingWallpaper.json:

{
    "logLevel": "Information",
    "apiServerUrl": "http://www.bing.com",
    "slideshowPath": "C:\\Users\\Public\\Pictures\\Slideshow",
    "firstRunDownloadCount": 8
}
  • slideshowPath: Pictures are saved here. Defaults to %public%\Pictures\Slideshow. Folder will be automatically created if not already exists.

  • firstRunDownloadCount: On first run, down this number of images. Defaults to the past 8 days. 8 is the maximum supported by Bing.com

  • apiServerUrl: the script will query this server for image metadata and download url. If you have an alternate server that implements Bing's, you can enter it here.

  • logLevel: Error, Warning, Information, Verbose. Defaults to 'Information'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.