none
Advanced Scheduled Task & TriggerSettings RRS feed

  • Question

  • I'm currently working on a script, that creates 2 scheduled task, and sets them to run once at a specific date. This works as intended, except for the fact I need to be able to set these task to expire, and delete themselves.

    Looking in the GUI at Scheduled Task, The settings tab has the first option I need, which is the "If the task is not scheduled to run again, delete it after: x amount of days." So, the first thing I take a look at is the help for Register-ScheduledTask, and notice there is a -Settings parameter, which accepts a CimInstance. Well I'm not sure exactly it means by a CimInstance. So, I figred I can figure out what it needs by taking a Get-ScheduledTask, and looking at Settings of it. I run Get-ScheduledTask 'Adobe Flash Player Updater' | Select -ExpandProperty Settings.

    This shows exactly what I'm looking for, the "DeleteExpiredTaskAfter" option, and the value. The value is listed odd though. It appears as P3D. So, I try entering -Settings DeleteExpiredTaskAfter 'P3D' enter my script, to test if that enables it, which it returns an error. How exactly am I supposed to call that setting into the Register-ScheduledTask?

    Also, with the New-ScheduledTaskTrigger command, is there no way to set a date or time for the trigger to expire? I don't see anything within the help on it.

    Friday, March 20, 2015 9:58 PM

Answers

All replies

  • Yes. PowerShell scheduled tasks are not ready for prime time. Use schtasks.

    schtasks -change -?

    You will find all settings.


    ¯\_(ツ)_/¯

    • Marked as answer by CoryH60 Saturday, March 21, 2015 12:09 AM
    Friday, March 20, 2015 10:15 PM
    • Marked as answer by CoryH60 Saturday, March 21, 2015 12:09 AM
    Friday, March 20, 2015 10:21 PM
    • Marked as answer by CoryH60 Saturday, March 21, 2015 12:09 AM
    Friday, March 20, 2015 10:28 PM
  • PT72H = 72 Hours
    PT2M - 2 Months

    etc..


    ¯\_(ツ)_/¯

    • Marked as answer by CoryH60 Saturday, March 21, 2015 12:09 AM
    Friday, March 20, 2015 10:32 PM
  •     <xs:complexType name="triggerBaseType" abstract="true">
            <xs:sequence>
                <xs:element name="Enabled"            type="xs:boolean"     default="true"  minOccurs="0" />
                <xs:element name="StartBoundary"      type="xs:dateTime"                    minOccurs="0" />
                <xs:element name="EndBoundary"        type="xs:dateTime"                    minOccurs="0" />
                <xs:element name="Repetition"         type="repetitionType"                 minOccurs="0" />
                <xs:element name="ExecutionTimeLimit" type="xs:duration"    default="PT72H" minOccurs="0" />
            </xs:sequence>
            <xs:attribute name="id" type="xs:ID" use="optional" />
        </xs:complexType>
    
    https://msdn.microsoft.com/en-us/library/windows/desktop/aa383609(v=vs.85).aspx

    ¯\_(ツ)_/¯

    • Marked as answer by CoryH60 Saturday, March 21, 2015 12:09 AM
    Friday, March 20, 2015 10:38 PM
  • PT72H = 72 Hours
    PT2M - 2 Months

    etc..


    ¯\_(ツ)_/¯

    Wow, thanks for all the great info. For some reason, I've had an incredibly hard time finding any information for what exactly I was looking for. I figured I could go the schtask route, but I really wanted to try and keep it PowerShell as much as I could. The info from Jeff is probably the route I was looking for.

    I knew I could also go with the New-ScheduledTaskSettings, but I wanted to try and keep from running a complete new line of code. Also, what does the PT stand for, if you don't mind me asking? Physical Time?


    Saturday, March 21, 2015 12:13 AM
  • . Also, what does the PT stand for, if you don't mind me asking? Physical Time?


    Good question. I went through that because I didn't know the answer myself but knew how to look for it.

    It is defined as a time interval of integer value with D,W,M as the variants.  I have to guess that PT ws just used as an identifier.


    ¯\_(ツ)_/¯

    Saturday, March 21, 2015 12:19 AM