none
Help with VB script needed RRS feed

  • Question

  • I want to search a string in my xml file "test.xml" and then replace the string with another one. Here is my xml (i know it might not be in the correct format)

    XML:

    <?xml version="1.0" encoding="UTF-16"?>

    <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">

      <RegistrationInfo>

        <Date>2011-09-27T00:29:57.4121302</Date>

        <Author>TEST\kausty</Author>

        <Description>This task is for testing purposes - Kausty</Description>

      </RegistrationInfo>

      <Triggers>

        <CalendarTrigger>

          <Repetition>

            <Interval>PT1H</Interval>

            <Duration>P1D</Duration>

            <StopAtDurationEnd>true</StopAtDurationEnd>

          </Repetition>

          <StartBoundary>2011-09-27T05:28:20.882923Z</StartBoundary>

          <EndBoundary>2012-09-27T05:40:20Z</EndBoundary>

          <ExecutionTimeLimit>P3D</ExecutionTimeLimit>

          <Enabled>false</Enabled>

          <RandomDelay>PT8H</RandomDelay>

          <ScheduleByWeek>

            <DaysOfWeek>

              <Sunday />

              <Monday />

              <Tuesday />

              <Friday />

            </DaysOfWeek>

     

    I want to search for <Sunday /> and replace it with <Sunday>TRUE</Sunday>.

    Please Help!! :) Thanks in advance. VB script would be good.


    • Edited by kausty88 Wednesday, October 12, 2011 3:48 PM
    Wednesday, October 12, 2011 3:46 PM

Answers

  • Hi,

    I suggest we go ahead and mark this question as answered for now. If you have specific questions about how to interact with the Schedule.Service COM object in a script, you can ask here.

    Bill

    • Marked as answer by kausty88 Monday, October 17, 2011 5:23 PM
    Monday, October 17, 2011 5:20 PM
    Moderator

All replies

  • Wednesday, October 12, 2011 3:59 PM
    Moderator
  • Since it is not a fully formed XML file, it might be best to use the FSO to alter it, maybe something like this ...

    inFN  = "testxml.txt"
    outFN = "outputxml.txt"
    with createobject("scripting.filesystemobject")
      sText = .opentextfile(inFN,1).readall
      sText = replace(sText, "<Sunday />", "<Sunday>TRUE</Sunday>")
      .opentextfile(outFN, 2, true).write stext
    end with

    The UTF=16 part is the only part I am uncertain about, as VBS scripts cannot handle that IOMode - just ANSI and Unicode.  The script above works on ANSI (ASCII) coded files only. 


    Tom Lavedas
    Wednesday, October 12, 2011 4:06 PM
    Moderator
  • Well,

    Tom: First of all, thanks for your prompt response. but this not working right now, as i tested this one and got the following error.

    It says: Invalid procedure call at line 6 char 3. 

    Well, maybe this script is good for .txt but might not be suited for .xml?

    I also tried to use this but this too failed to work.

    Set objFS = CreateObject("Scripting.FileSystemObject")

    strFile=WScript.Arguments.Item(0)

    strOld=WScript.Arguments.Item(1)

    strNew=WScript.Arguments.Item(2)

    Set objFile = objFS.OpenTextFile(strFile)

    Do Until objFile.AtEndOfStream

     strLine = objFile.ReadLine 

            if Instr(strLine,strOld)> 0 Then

              strLine=Replace(strLine,strOld,strNew)

            End If

     WScript.Echo strLine

    Loop

    I tired to use the MSSSXMLDOM object as well, still that did not work. Any better way if you can think of at the top of your head? Even a .bat script would do if not possible with the vb script. :)

    Thanks for you response man!!


    kkk
    Wednesday, October 12, 2011 5:33 PM
  • Hi,

    It seems that you could use the Schedule.Service object if what you want to do is modify scheduled tasks.

    Bill

    Wednesday, October 12, 2011 5:45 PM
    Moderator
  • Bill,

    Awesome, you have any examples for this? today i spent my entire day hitting around these thing but could not find and worth while. if you have anything under this pretext, would help a lot!! :) 

    Thanks!

     


    Kausty :)
    Wednesday, October 12, 2011 5:50 PM
  • Wednesday, October 12, 2011 6:08 PM
    Moderator
  • Your file is horrbly broken.

    If you get one that is intact it can be edited with MSXML.

     

     


    jv
    Wednesday, October 12, 2011 7:27 PM
  • I just dumped an XML task file loaded it in MSXML and edited it with not problems. ALl Task as saved as UTF-16

    Here is one of the Microsoft default tasks from Windows 7.

    <?xml version="1.0" encoding="UTF-16"?>
    <Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
      <RegistrationInfo>
        <Source>Microsoft Corporation</Source>
        <Author>Microsoft Corporation</Author>
        <Version>1.0</Version>
        <Description>Aggregates and uploads Application Telemetry information if opted-in to the Microsoft Customer Experience Improvement Program.</Description>
        <URI>\Microsoft\Windows\Application Experience\AitAgent</URI>
        <SecurityDescriptor>D:(A;;GA;;;BA)(A;;GA;;;SY)</SecurityDescriptor>
      </RegistrationInfo>
      <Triggers>
        <CalendarTrigger>
          <StartBoundary>2007-10-08T02:30:00</StartBoundary>
          <Enabled>true</Enabled>
          <ScheduleByDay>
            <DaysInterval>1</DaysInterval>
          </ScheduleByDay>
        </CalendarTrigger>
      </Triggers>
      <Principals>
        <Principal id="LocalSystem">
          <UserId>S-1-5-18</UserId>
          <RunLevel>LeastPrivilege</RunLevel>
        </Principal>
      </Principals>
      <Settings>
        <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
        <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
        <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
        <AllowHardTerminate>true</AllowHardTerminate>
        <StartWhenAvailable>true</StartWhenAvailable>
        <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
        <IdleSettings>
          <Duration>PT3M</Duration>
          <WaitTimeout>PT22H</WaitTimeout>
          <StopOnIdleEnd>true</StopOnIdleEnd>
          <RestartOnIdle>true</RestartOnIdle>
        </IdleSettings>
        <AllowStartOnDemand>true</AllowStartOnDemand>
        <Enabled>true</Enabled>
        <Hidden>false</Hidden>
        <RunOnlyIfIdle>true</RunOnlyIfIdle>
        <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
        <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
        <WakeToRun>false</WakeToRun>
        <ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
        <Priority>9</Priority>
      </Settings>
      <Actions Context="LocalSystem">
        <Exec>
          <Command>aitagent</Command>
        </Exec>
      </Actions>
    </Task>
    

    Note that this is a comlpete file.

    It is relatively easy to export tasks, modify them and import back.

    Here is the direct write method.

    $xmlDoc.Task.Triggers.CalendarTrigger.ScheduleByWeek.DaysOfWeek.Sunday='true'

    Just save it and you are done.

    $xmlDoc.Save()

     

     


    jv
    • Edited by jrv Wednesday, October 12, 2011 8:37 PM
    Wednesday, October 12, 2011 7:33 PM
  • Hi jv,

    I think he is looking to modify scheduled tasks from a script, in which case it would make sense to make use of the COM object rather than try to edit the XML file directly.

    Bill

    Wednesday, October 12, 2011 8:39 PM
    Moderator
  • Hi jv,

    I think he is looking to modify scheduled tasks from a script, in which case it would make sense to make use of the COM object rather than try to edit the XML file directly.

    Bill


    I post it because sometines we have an exported template XML file and it i s easilr to edit teh xml in batch thatn it is to use the COM object to load edit then save.  In Posh it cam be done in a couple of lines.

    The COM object is good for adding and updating existing tasks.  Not  sure what is needed here so both solutions are now available.

     

     


    jv
    • Edited by jrv Wednesday, October 12, 2011 9:05 PM
    Wednesday, October 12, 2011 9:04 PM
  • Guys,

    Here is my complete original XML:

    <?xml version="1.0" encoding="UTF-16"?>
    <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
      <RegistrationInfo>
        <Date>2011-09-27T00:29:57.4121302</Date>
        <Author>TEST\kausty</Author>
        <Description>This task is for testing purposes</Description>
      </RegistrationInfo>
      <Triggers>
        <CalendarTrigger>
          <Repetition>
            <Interval>PT1H</Interval>
            <Duration>P1D</Duration>
            <StopAtDurationEnd>true</StopAtDurationEnd>
          </Repetition>
          <StartBoundary>2011-09-27T05:28:20.882923Z</StartBoundary>
          <EndBoundary>2012-09-27T05:40:20Z</EndBoundary>
          <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
          <Enabled>false</Enabled>
          <RandomDelay>PT8H</RandomDelay>
          <ScheduleByWeek>
            <DaysOfWeek>
              <Sunday />
              <Monday />
              <Tuesday />
              <Friday />
            </DaysOfWeek>
            <WeeksInterval>1</WeeksInterval>
          </ScheduleByWeek>
        </CalendarTrigger>
        <CalendarTrigger>
          <Repetition>
            <Interval>PT1H</Interval>
            <Duration>P1D</Duration>
            <StopAtDurationEnd>true</StopAtDurationEnd>
          </Repetition>
          <StartBoundary>2011-09-27T00:28:55.7216716</StartBoundary>
          <EndBoundary>2012-09-29T03:19:50.3715578</EndBoundary>
          <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
          <Enabled>false</Enabled>
          <RandomDelay>PT1H</RandomDelay>
          <ScheduleByWeek>
            <DaysOfWeek>
              <Tuesday />
            </DaysOfWeek>
            <WeeksInterval>1</WeeksInterval>
          </ScheduleByWeek>
        </CalendarTrigger>
        <CalendarTrigger>
          <Repetition>
            <Interval>PT1H</Interval>
            <Duration>P1D</Duration>
            <StopAtDurationEnd>true</StopAtDurationEnd>
          </Repetition>
          <StartBoundary>2011-09-27T12:55:25.1643185Z</StartBoundary>
          <EndBoundary>2012-09-29T08:19:59.2782143Z</EndBoundary>
          <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
          <Enabled>false</Enabled>
          <RandomDelay>PT1H</RandomDelay>
          <ScheduleByMonthDayOfWeek>
            <Weeks>
              <Week>2</Week>
            </Weeks>
            <DaysOfWeek>
              <Wednesday />
            </DaysOfWeek>
            <Months>
              <January />
              <February />
              <March />
              <April />
              <May />
              <June />
              <July />
              <August />
              <September />
              <October />
              <November />
              <December />
            </Months>
          </ScheduleByMonthDayOfWeek>
        </CalendarTrigger>
        <CalendarTrigger>
          <Repetition>
            <Interval>PT1H</Interval>
            <Duration>P1D</Duration>
            <StopAtDurationEnd>true</StopAtDurationEnd>
          </Repetition>
          <StartBoundary>2011-09-27T07:56:13.9679498</StartBoundary>
          <EndBoundary>2012-09-29T03:20:21.2426288</EndBoundary>
          <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
          <Enabled>false</Enabled>
          <RandomDelay>PT1H</RandomDelay>
          <ScheduleByMonth>
            <DaysOfMonth>
              <Day>18</Day>
            </DaysOfMonth>
            <Months>
              <January />
              <February />
              <March />
              <April />
              <May />
              <June />
              <July />
              <August />
              <September />
              <October />
              <November />
              <December />
            </Months>
          </ScheduleByMonth>
        </CalendarTrigger>
        <CalendarTrigger>
          <Repetition>
            <Interval>PT1H</Interval>
            <Duration>P1D</Duration>
            <StopAtDurationEnd>true</StopAtDurationEnd>
          </Repetition>
          <StartBoundary>2011-09-29T08:04:09.4610608Z</StartBoundary>
          <EndBoundary>2012-09-29T08:20:51.5014353Z</EndBoundary>
          <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
          <Enabled>false</Enabled>
          <RandomDelay>PT1H</RandomDelay>
          <ScheduleByDay>
            <DaysInterval>1</DaysInterval>
          </ScheduleByDay>
        </CalendarTrigger>
      </Triggers>
      <Principals>
        <Principal id="Author">
          <RunLevel>HighestAvailable</RunLevel>
          <UserId>TEST\kausty</UserId>
          <LogonType>Password</LogonType>
        </Principal>
      </Principals>
      <Settings>
        <IdleSettings>
          <Duration>PT10M</Duration>
          <WaitTimeout>PT1H</WaitTimeout>
          <StopOnIdleEnd>true</StopOnIdleEnd>
          <RestartOnIdle>true</RestartOnIdle>
        </IdleSettings>
        <MultipleInstancesPolicy>Queue</MultipleInstancesPolicy>
        <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
        <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
        <AllowHardTerminate>true</AllowHardTerminate>
        <StartWhenAvailable>true</StartWhenAvailable>
        <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
        <AllowStartOnDemand>true</AllowStartOnDemand>
        <Enabled>true</Enabled>
        <Hidden>false</Hidden>
        <RunOnlyIfIdle>true</RunOnlyIfIdle>
        <WakeToRun>false</WakeToRun>
        <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
        <DeleteExpiredTaskAfter>P30D</DeleteExpiredTaskAfter>
        <Priority>7</Priority>
        <RestartOnFailure>
          <Interval>PT1M</Interval>
          <Count>3</Count>
        </RestartOnFailure>
      </Settings>
      <Actions Context="Author">
        <Exec>
          <Command>C:\test\test.bat</Command>
          <Arguments>&gt;&gt; C:\test\test.log</Arguments>
        </Exec>
      </Actions>
    </Task>

    And now i am looking for a script (Vb preferably) to make my xml script look this:

    <?xml version="1.0" encoding="UTF-16"?>
    <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
      <RegistrationInfo>
        <Date>2011-09-27T00:29:57.4121302</Date>
        <Author>TEST\kausty</Author>
        <Description>This task is for testing purposes</Description>
      </RegistrationInfo>
      <Triggers>
        <CalendarTrigger>
          <Repetition>
            <Interval>PT1H</Interval>
            <Duration>P1D</Duration>
            <StopAtDurationEnd>true</StopAtDurationEnd>
          </Repetition>
          <StartBoundary>2011-09-27T05:28:20.882923Z</StartBoundary>
          <EndBoundary>2012-09-27T05:40:20Z</EndBoundary>
          <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
          <Enabled>false</Enabled>
          <RandomDelay>PT8H</RandomDelay>
          <ScheduleByWeek>
            <DaysOfWeek>
              <Sunday>TRUE</Sunday>
              <Monday>TRUE</Monday>
              <Tuesday>TRUE</Tuesday>
              <Friday>TRUE</Friday>
            </DaysOfWeek>
            <WeeksInterval>1</WeeksInterval>
          </ScheduleByWeek>
        </CalendarTrigger>
        <CalendarTrigger>
          <Repetition>
            <Interval>PT1H</Interval>
            <Duration>P1D</Duration>
            <StopAtDurationEnd>true</StopAtDurationEnd>
          </Repetition>
          <StartBoundary>2011-09-27T00:28:55.7216716</StartBoundary>
          <EndBoundary>2012-09-29T03:19:50.3715578</EndBoundary>
          <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
          <Enabled>false</Enabled>
          <RandomDelay>PT1H</RandomDelay>
          <ScheduleByWeek>
            <DaysOfWeek>
              <Tuesday>TRUE</Tuesday>
            </DaysOfWeek>
            <WeeksInterval>1</WeeksInterval>
          </ScheduleByWeek>
        </CalendarTrigger>
        <CalendarTrigger>
          <Repetition>
            <Interval>PT1H</Interval>
            <Duration>P1D</Duration>
            <StopAtDurationEnd>true</StopAtDurationEnd>
          </Repetition>
          <StartBoundary>2011-09-27T12:55:25.1643185Z</StartBoundary>
          <EndBoundary>2012-09-29T08:19:59.2782143Z</EndBoundary>
          <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
          <Enabled>false</Enabled>
          <RandomDelay>PT1H</RandomDelay>
          <ScheduleByMonthDayOfWeek>
            <Weeks>
              <Week>2</Week>
            </Weeks>
            <DaysOfWeek>
              <Wednesday>TRUE</Wednesday>
            </DaysOfWeek>
            <Months>
              <January>TRUE</January>
              <February>TRUE</February>
              <March>TRUE</March>
              <April>TRUE</April>
              <May>TRUE</May>
              <June>TRUE</June>
              <July>TRUE</July>
              <August>TRUE</August>
              <September>TRUE</September>
              <October>TRUE</October>
              <November>TRUE</November>
              <December>TRUE</December>
            </Months>
          </ScheduleByMonthDayOfWeek>
        </CalendarTrigger>
        <CalendarTrigger>
          <Repetition>
            <Interval>PT1H</Interval>
            <Duration>P1D</Duration>
            <StopAtDurationEnd>true</StopAtDurationEnd>
          </Repetition>
          <StartBoundary>2011-09-27T07:56:13.9679498</StartBoundary>
          <EndBoundary>2012-09-29T03:20:21.2426288</EndBoundary>
          <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
          <Enabled>false</Enabled>
          <RandomDelay>PT1H</RandomDelay>
          <ScheduleByMonth>
            <DaysOfMonth>
              <Day>18</Day>
            </DaysOfMonth>
            <Months>
              <January>TRUE</January>
              <February>TRUE</February>
              <March>TRUE</March>
              <April>TRUE</April>
              <May>TRUE</May>
              <June>TRUE</June>
              <July>TRUE</July>
              <August>TRUE</August>
              <September>TRUE</September>
              <October>TRUE</October>
              <November>TRUE</November>
              <December>TRUE</December>
            </Months>
          </ScheduleByMonth>
        </CalendarTrigger>
        <CalendarTrigger>
          <Repetition>
            <Interval>PT1H</Interval>
            <Duration>P1D</Duration>
            <StopAtDurationEnd>true</StopAtDurationEnd>
          </Repetition>
          <StartBoundary>2011-09-29T08:04:09.4610608Z</StartBoundary>
          <EndBoundary>2012-09-29T08:20:51.5014353Z</EndBoundary>
          <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
          <Enabled>false</Enabled>
          <RandomDelay>PT1H</RandomDelay>
          <ScheduleByDay>
            <DaysInterval>1</DaysInterval>
          </ScheduleByDay>
        </CalendarTrigger>
      </Triggers>
      <Principals>
        <Principal id="Author">
          <RunLevel>HighestAvailable</RunLevel>
          <UserId>TEST\kausty</UserId>
          <LogonType>Password</LogonType>
        </Principal>
      </Principals>
      <Settings>
        <IdleSettings>
          <Duration>PT10M</Duration>
          <WaitTimeout>PT1H</WaitTimeout>
          <StopOnIdleEnd>true</StopOnIdleEnd>
          <RestartOnIdle>true</RestartOnIdle>
        </IdleSettings>
        <MultipleInstancesPolicy>Queue</MultipleInstancesPolicy>
        <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
        <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
        <AllowHardTerminate>true</AllowHardTerminate>
        <StartWhenAvailable>true</StartWhenAvailable>
        <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
        <AllowStartOnDemand>true</AllowStartOnDemand>
        <Enabled>true</Enabled>
        <Hidden>false</Hidden>
        <RunOnlyIfIdle>true</RunOnlyIfIdle>
        <WakeToRun>false</WakeToRun>
        <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
        <DeleteExpiredTaskAfter>P30D</DeleteExpiredTaskAfter>
        <Priority>7</Priority>
        <RestartOnFailure>
          <Interval>PT1M</Interval>
          <Count>3</Count>
        </RestartOnFailure>
      </Settings>
      <Actions Context="Author">
        <Exec>
          <Command>C:\test\test.bat</Command>
          <Arguments>&gt;&gt; C:\test\test.log</Arguments>
        </Exec>
      </Actions>
    </Task>

    I tried you examples but since a beginner could not get this done. I DON'T want to edit my original XML files but just want to edit these backup which I have copied  to a folder.

    Help!!


    Kausty :)
    Thursday, October 13, 2011 5:47 AM
  • So you see it is not what you originally asked for. 

    Why don't you fully explain what you are trying to do and why.

     


    jv
    Thursday, October 13, 2011 8:37 AM
  • I want to make the schema consistent for this xml. When I am using my ETL tools it cannot parse <Sunday /> as it is not a correct node for the tool. What it recognizes is this <Sunday>TRUE</Sunday> where it creates a column in the table with the name sunday and then stores the value TRUE for that row. The tool i am using for extracting the data from XML is Pentaho (XML file input). So I want to convert my file in that format.
    Kausty :)
    Thursday, October 13, 2011 9:34 AM
  • I want to make the schema consistent for this xml. When I am using my ETL tools it cannot parse <Sunday /> as it is not a correct node for the tool. What it recognizes is this <Sunday>TRUE</Sunday> where it creates a column in the table with the name sunday and then stores the value TRUE for that row. The tool i am using for extracting the data from XML is Pentaho (XML file input). So I want to convert my file in that format.
    Kausty :)


    Unfortualy tis is a scripting forum and we know nothing about your tool.

    THe XML is not a convertible format.  

    We can load it into MSXML and edit it.  We cannot covert it to some other format.  It will become useless if it's format or 'schema' is changed.

    No tool can edit this XML unless it knows how to manage namespaces.  The default namespace in this document has to be referenced.  We need to create an alias. for the namespace using the namespace manager.

    The other possibility is to load the XML into a Task object as suggested above.  You can then use the 'settings' object to alter the task and then save it back out to XML.

    The other earlier suggestion to just search for and update the string is also doable. 

    Converting to another format is either up to you or up to the tool vendor whose tool  you want to use.

    Any of these suggestions require that you at least make some attempt to write a script as we can only help you in this. The actual script is up to you.

    FIrst choose what you want to do.

     

     


    jv
    Thursday, October 13, 2011 11:12 AM
  • Hi,

    If the purpose behind all of this is to make changes to scheduled tasks, then I recommend using the TaskService COM object.

    Bill

    Thursday, October 13, 2011 2:18 PM
    Moderator
  • Yeh, working on this one!! Still scratching my head on this one, want to get this done anyhow.....lets see where do i land with this.

     Thanks!!


    Kausty :)
    Monday, October 17, 2011 4:42 PM
  • Hi,

    I suggest we go ahead and mark this question as answered for now. If you have specific questions about how to interact with the Schedule.Service COM object in a script, you can ask here.

    Bill

    • Marked as answer by kausty88 Monday, October 17, 2011 5:23 PM
    Monday, October 17, 2011 5:20 PM
    Moderator
  • Yeh, working on this one!! Still scratching my head on this one, want to get this done anyhow.....lets see where do i land with this.

     Thanks!!


    Kausty :)


    Here is the XML method (again)

    $nsmgr.AddNamespace('df','http://schemas.microsoft.com/windows/2004/02/mit/task')
    $nodes=$task.SelectNodes('//df:Sunday',$nsmgr)
    $nodes |
         ForEach-Object{
                       if($_.innerText){
                            $_.innerText = 'True'
                       }else{
                            $el=$task.CreateTextNode('True')
    	    $_.AppendChild($el)
                       }
         }
    $task.Save("$pwd\newtask.xml"
    

    This will update all references to 'Sunday' and eeither change the setting to True or add a 'True' setting.

    I have experimented the scheduler object.  Creating Tasks with COm is far harder ethat doing it with XML.  The biggest issue with XML is that the XML schema is not well documented but then neither is the Scheduler object. 

    Stay tuned for Net Framework class solution.

     


    jv
    Monday, October 17, 2011 6:35 PM
  • I have experimented the scheduler object.  Creating Tasks with COm is far harder ethat doing it with XML.

    This would be a matter of opinion; but in any case, this question is already marked answered. If you prefer a different way, feel free to post a code sample in a discussion thread.

    Bill

    Monday, October 17, 2011 6:44 PM
    Moderator
  • I have experimented the scheduler object.  Creating Tasks with COm is far harder ethat doing it with XML.

    This would be a matter of opinion; but in any case, this question is already marked answered. If you prefer a different way, feel free to post a code sample in a discussion thread.

    Bill


    Sorry Bill but the OP posted baxck and I was answering his statement more directly.

    If you have a solution using the Scheduler Object then feel free to post it.  I don't think it is very easy to use the object to edit an XML template file.  Using string editing won't work easily either as teh weekly values can be embedded in varying ways. Treating the structure like th eXML it is allows us to account for all of these issues.

    The future of these things is going the way of the Event Logs. All is moving to XML and XPath.  The Scheduler uses this internally.  I am sure it will be enhanced to allow for more meaningful and intuitive edits.

     


    jv
    Monday, October 17, 2011 6:56 PM