Kaseya Community

"Write text to file" not actually writing text to file.

  • I'm somewhat new to Kaseya scripting so this may very well be an error on my part, but I'm trying to create a script using the "write text to file" step and it isn't working.  The "text to write" parameter is set to #global:cmdresults# and the target folder\file is "C:\temp\#vAgentConfiguration.workgroupDomainName#.csv".  There is definitely data in #global:cmdresults# as other steps are able to utilize it, but when I try to get file from the write text step it fails with "file open failed" in the procedure log.  I've watched the destination directory while the script was running, and while other temp files related to the script are created and deleted my target file never even shows up.  

     

     

    Am I doing something wrong?

  • David, it happens when the process doesn't have enough time to execute before the next step in the procedure gets executed, use the option of "Wait for the program to complete before continuing" check box if you have one under your steps or else add the step "Pause this procedure for N seconds to give a previous action time to complete." and put in a 10 second delay.

  • Procedure Send list of AD email addresses - dl(2).xml

    I added a 10 second delay right after the step that creates the file, it's still not working.  I've attached the procedure in its entirety for reference.

  • you are getting the details in your email but the text is not getting written to file?

  • I just tested the write text to file function, I can get it to write normal text input but it's failing when I use #global:cmdresults# variable,

    I think It would be simpler to just add an additional command to pipe the result to csv file under step 3.

  • I actually already tried that, the first version of the script I made piped the results directly to file.  Except once again, no file is written and the results are output to console.  For reference, the command I used is:

    #vAgentConfiguration.AgentTempDir#\adfind.exe -default -f "&(objectcategory=person)(objectclass=user)" givenname sn mail -nodn -csv >> "#vAgentConfiguration.AgentTempDir#\#vAgentConfiguration.workgroupDomainName#.csv"

  • This worked fine for me. The file was written and the results were emailed to me. You'll need to change the email address back to yours and I changed the location that the file is written to on the KServer to "C:\Temp". Not sure if that mattered or not.

     

    <?xml version="1.0" encoding="utf-8"?>

    <ScriptExport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.kaseya.com/vsa/2008/12/Scripting">

      <Procedure name="Send list of AD email addresses - dl" treePres="3" id="1234924308" folderId="21246231921621776498221953">

        <Body description="This procedure queries AD and creates a CSV containing all users and their primary email addresses, then mails it to Kim.&#xA;">

          <If description="">

            <Condition name="True" />

            <Then>

              <Statement description="Write the selected file to the machine at the path specified - full path required." name="WriteFile" continueOnFail="false" osType="Windows">

                <Parameter xsi:type="StringParameter" name="Path" value="#vAgentConfiguration.AgentTempDir#\adfind.exe" />

                <Parameter xsi:type="StringParameter" name="ManagedFile" value="VSASharedFiles\AdFind.exe" />

                <Parameter xsi:type="BooleanParameter" name="DeleteAfter" value="False" />

              </Statement>

              <Statement description="Attempts to return results of a shell command to a global variable '#global:cmdresults#'" name="Execute Shell Command - Get Results to Variable" continueOnFail="false">

                <Parameter xsi:type="StringParameter" name="Parameter1" value="#vAgentConfiguration.AgentTempDir#\adfind.exe -default -f &quot;&amp;(objectcategory=person)(objectclass=user)&quot; givenname sn mail -nodn -csv" />

                <Parameter xsi:type="StringParameter" name="Parameter2" value="false" />

                <Parameter xsi:type="StringParameter" name="Parameter3" value="User" />

              </Statement>

              <Statement description="Pause this procedure for N seconds to give a previous action time to complete." name="PauseScript" continueOnFail="false">

                <Parameter xsi:type="IntegerParameter" name="Seconds" value="10" />

              </Statement>

              <Statement description="Send an email from the server (address specified in the Configure function in the System module)." name="SendEmail" continueOnFail="false" osType="Windows">

                <Parameter xsi:type="StringParameter" name="To" value="placeholder@domainname.com" />

                <Parameter xsi:type="StringParameter" name="Subject" value="ADfind Results" />

                <Parameter xsi:type="StringParameter" name="Body" value="#global:cmdresults#" />

              </Statement>

              <Statement description="Write text to file" name="Write text to file" continueOnFail="false">

                <Parameter xsi:type="StringParameter" name="Parameter1" value="#global:cmdresults#" />

                <Parameter xsi:type="StringParameter" name="Parameter2" value="#vAgentConfiguration.AgentTempDir#\#vAgentConfiguration.workgroupDomainName#.csv&quot;" />

                <Parameter xsi:type="StringParameter" name="Parameter3" value="True" />

              </Statement>

              <Statement description="Get the specified file - full path to file required." name="GetFile" continueOnFail="false" osType="Windows">

                <Parameter xsi:type="StringParameter" name="RemoteFileName" value="&quot;#vAgentConfiguration.AgentTempDir#\#vAgentConfiguration.workgroupDomainName#.csv&quot;" />

                <Parameter xsi:type="StringParameter" name="KServerFileName" value="C:\Temp\#vAgentConfiguration.workgroupDomainName#.csv&quot;" />

                <Parameter xsi:type="EnumParameter" name="Action" value="SaveExistingNoAlert" />

              </Statement>

            </Then>

          </If>

        </Body>

      </Procedure>

    </ScriptExport>