locked
Group Policy Scheduled task to run only if connected on the network RRS feed

  • Question

  • Hello everyone

    I'm not sure if this is possible, but I wanted to post here and get any suggestions I can. I have created a script that collects from logs from a program our mobile users depend on in the field. The script copies a few log files that the program saves to the local drive which we can use to diagnose problems if the user reports they are have difficulties. As our users work in the field a lot, scheduling a time to work with them is one of the largest delays we have in getting problems resolved.

    To combat this, the script I have created will copy these log files to a shared folder on our network which could then be references should users complain they have experiencing issues. The script works as designed, but I am unsure the best way to set up the scheduled task.

    I would like to create a Group Policy scheduled task for OU these computers are in, but the task should only run when the computer is connected to our network. Ideally, if possible, I would like to be able to have the task run as soon as it detects a connection to the network - but I do not see options to allow this.

    Does anyone have any suggestions on how to set up a task to run only if connected to our network, or when it connects?


    Richard A Jahnke

    Friday, May 17, 2013 3:01 PM

Answers

  • Hi Richard,

    Windows Vista and later can run scheduled tasks on triggers as well as schedules so it depends on the client OS. I haven't used these before but you could use one of the built-in triggers (at logon, at startup etc..). But if they're in the field a lot and the VPN connection doesn't happen before logon then you may want to go with "On an event" and see if your VPN logs something when it connects or if the network profile changes to domain (Applications and Services Logs\Microsoft\Windows\NetworkProfile\Operational).

    The other option with Scheduled Tasks would be to have multiple schedules per day and check they can get to the path (eg. test-path if your using PowerShell: http://technet.microsoft.com/en-us/library/ee177015.aspx) before attempting the upload.

    With either option, it's probably worth putting a flag file of some sort in the source directory when a successful upload occurs. You could then check the date of this file each time the script runs so you don't have more than x uploads attempted per day. In Powershell, something like the below may do it:

    If (!(Get-ChildItem -Filter uploadflag.txt | ?{(((Get-Date).AddHours(-24) - $_.LastWriteTime) -lt 1)})){Write-Host "Upload"}Else{Write-Host "Already done today"}

    Alternatively, if you already have folder redirection\offline files in place, you could upload the files to there once a day and let the sync deal with getting them back to the network whenever it can.

    I hope this helps,

    Mark.

    Ps. Have a look at this post for information on Network Location Awareness: http://social.technet.microsoft.com/Forums/en-US/winserverGP/thread/bf625c14-7ac5-452a-be2d-69221a76afdb
    • Edited by - Mark - Monday, May 20, 2013 10:13 AM Added Network Location Awareness link
    • Marked as answer by Andy Qi Tuesday, May 28, 2013 10:10 AM
    Monday, May 20, 2013 9:52 AM