Washington DC Endpoint Management User Group

 View Only
  • 1.  Task Server Task and Batch Variables

    Posted Mar 20, 2013 11:35 PM
    Is there a way to have a task server task use custom dos variables in a batch task? The example below works fine as a client task but does not work in a "Run Script on Task Server" task. %this% is empty when it should return "that". SET This=That ECHO %this%


  • 2.  RE: Task Server Task and Batch Variables

    Posted Mar 26, 2013 10:18 AM

    I'm guessing this isn't the real question you have - but there's something you're trying to do that isn't specified here.

     

    First, it "seems" to me that this should work.  You may want to call support to see why it doesn't as it could be a defect... I don't know.

     

    Second, there may be a better way to accomplish what you want.

     

    Just a thought.  If you share what you're trying to do, maybe we can help find a work-around / another way.



  • 3.  RE: Task Server Task and Batch Variables

    Posted Mar 26, 2013 11:52 AM

    True ... just tried.

    Not even

    echo %time%

    works as Task Server Script.



  • 4.  RE: Task Server Task and Batch Variables

    Posted Mar 26, 2013 04:40 PM

    Looking into the limitations of task server scripts.  Thanks for sharing.



  • 5.  RE: Task Server Task and Batch Variables

    Posted Mar 26, 2013 05:04 PM

    Thanks guys.... here is what we were doing and why it became an issue.

    We are starting a hardware migration and we are using PCT to move the users data and settings to the new hardware. However we have multiple sites and our IT Department is mostly in our DC office. Our Help Desk will be building new computers in our DC office for users in our remote office and we needed a way to move the data between sites. So I built a tokenized script that starts a PCT capture and saves the data to the local site's task server. We then needed a way for the restore job to "Hunt Down" where that users PCT data was saved and copy it to the local site server that the new computer is connected to. For performance sake we wanted the "Hunt and Copy" task to be a task server task since the data is really moving from one site server to another.

    We worked around this issue by building a VBS Task Server script and hardcoding our taskservers into an array variable since you don't need to use the % to call a variable.

     

    VBS

    Sub sDelete_Files(FromPath, CompGuid)
     'On error resume next
     set oFolder=FSO.getfolder(FromPath)
     FOR EACH oFile IN oFolder.files
      If Instr(1,oFile.Name,CompGuid,1) THEN
                           wscript.echo "Deleting: " & oFile.Name'oFile.delete
                           oFile.delete
      End IF
     NEXT
    End Sub 
     
    Function fCheckForFile(filePath)
        If FSO.FileExists(filePath) = False Then
           fCheckForFile = 0
        ELSE
      fCheckForFile = 1
     End If
    End Function 

    ' ---------------------------Main ------------------------------------------------------------------------ 
    Dim FSO    'File System Object
    Dim FromPath  'Personality Upload Task Server
    Dim ToPath   'Current Task Server
    Dim CompGuid  'Computer GUID
    Dim PersonalityEXE 'Personality .exe full file name


    Dim aTaskServerArray(4)
     aTaskServerArray(0) = "\\site1.mydomain.com\Personality\"
     aTaskServerArray(1) = "\\site2.mydomain.com\Personality\"
     aTaskServerArray(2) = "\\site3.mydomain.com\Personality\"
     aTaskServerArray(3) = "\\site4.mydomain.com\Personality\"
     aTaskServerArray(4) = "\\site5.mydomain.com\Personality\"


    Set args = WScript.Arguments
    ToPath = "%TASKSERVER%"
    CompGuid=Replace(ToPath, Chr(34), "")
    'wscript.echo "ToPath: " & ToPath
    ToPath = "\\" & ToPath & ".mydomain.com\Personality\"

    CompGuid = "%OwnerGuid%"
    CompGuid=Replace(CompGuid, Chr(34), "")
    PersonalityEXE = CompGuid & ".EXE"

    Set FSO = CreateObject("scripting.filesystemobject")

    'Does Personality capture exist on current task server?
    PersonalityEXEOnCurrentTaskServer = fCheckForFile(ToPath & PersonalityEXE)
    'If so, we're done. If not, find it.
    IF PersonalityEXEOnCurrentTaskServer = 0 THEN
     FOR x = 0 TO ubound(aTaskServerArray)
      PersonalityEXEOnCurrentTaskServer = fCheckForFile(aTaskServerArray(x) & PersonalityEXE)
      IF PersonalityEXEOnCurrentTaskServer = 1 THEN FromPath=aTaskServerArray(x) 'When found, save the original upload path in FromPath
     NEXT
     IF Len(FromPath) < 2 Then Wscript.Quit(2) 'If an original upload was not detected anywhere, exit with error 2
     'wscript.echo FromPath & CompGuid & " ToPath: " & ToPath
     Call sCopy_Files(FromPath, CompGuid, ToPath)
    END IF

    'check for personality.exe file.
    PersonalityEXEOnCurrentTaskServer = fCheckForFile(ToPath & PersonalityEXE)
    IF PersonalityEXEOnCurrentTaskServer = 0 THEN
     Wscript.Quit(3) 'Exit 3 if desired file does not exist on NEW task server.
    ELSE
     Call sDelete_Files(FromPath, CompGuid)'Delete files from original server.
    END IF



  • 6.  RE: Task Server Task and Batch Variables

    Posted Mar 26, 2013 05:27 PM

    Cool guys.  I know what's happening, but I don't know why yet.

    echo %time% >> c:\temp\time.txt

     

    If you put that in a server script task, you'll get "Echo is on" in the output.  Send that to a client PC, and you'll get the time.
     
    As I wrote to the task team about this, it occurred to me the difference, because I couldn't figure out why the text file had "Echo is on" in it, instead of the time.  Yeah, the script ran.
     
    What happened, is that %time% was interpreted as a token, and "replaced" with nothing, because there was no matching task token for that variable.  This is exactly the same format we use for task tokens, and because it's not defined as an actual token, it was stripped.  The resulting text looks like this:
     
    echo >> c:\temp\time.txt
     
    and guess what?  That will give you "Echo is on" as well.
     
    So we know what's going on, just not why.  And yes, I'm asking if that's a known limitation or not.  You might want to open a case on this to track the result, but I'll try to keep up with it here too.

     



  • 7.  RE: Task Server Task and Batch Variables

    Posted Mar 26, 2013 06:05 PM

    Yeah, that's obvious.

    The questions is, why there are two different token handlings:

    - Client task: unknown token -> don't touch (keep the environment variable)

    - Task Server task: unknown token -> replace (with "nothing" - wreck the environment variable)



  • 8.  RE: Task Server Task and Batch Variables

    Posted Mar 26, 2013 06:21 PM

    Yup.  I'm asking.  Trust me.



  • 9.  RE: Task Server Task and Batch Variables

    Posted Mar 27, 2013 04:28 PM

    OK folks - here's the news for all watching this:  We have a defect logged, AND it is "fixed" and should be out in the V4 Rollup, which is expected in about a week.

    Having said that, I'll believe it when I personally test it, but still, that's the official news, so here's hoping that in a week or so we can all sigh and feel good about these tasks.  :D