Kaseya Community

Passing kaseya script variable to vbs script

  • It is possible to input your kaseya variables into vbs script files using a simple find replace tool. (replace.vbs).

    Download replace.vbs as part of your kaseya script, and use it to search a vbs script file (or any other file) for certain text, and then replace that text with your kaseya variable, i.e:

    c:\temp\replace.vbs modifyfile.vbs oldtext #newtext#

    -----------------
    Replace.vbs

    Const ForReading = 1
    Const ForWriting = 2

    strFileName = Wscript.Arguments(0)
    strOldText = Wscript.Arguments(1)
    strNewText = Wscript.Arguments(2)

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile(strFileName, ForReading)

    strText = objFile.ReadAll
    objFile.Close
    strNewText = Replace(strText, strOldText, strNewText)

    Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
    objFile.WriteLine strNewText
    objFile.Close

    Legacy Forum Name: Passing kaseya script variable to vbs script,
    Legacy Posted By Username: myArch-man
  • Seems logical to me. As long as the tool can ba ran in a hidden DOS window I dont see why it would not work.

    God Bless,
    Marty

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Missing Link
  • We run a few scripts using kaseya variables and they work fine.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: bob.penland@kaseya.com
  • bpenland
    We run a few scripts using kaseya variables and they work fine.


    Can you explain the method you're using to accomplish this?

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: syscal
  • Basically, you're replacing known text in a vbs script with a kaseya variable.

    For example, you want to replace the text "C:\temp" in a vbs script file named backup.vbs with a variable you have defined for the agent temp directory.

    i.e.

    replace.vbs "c:\path\backup.vbs" "c:\temp" "#atemp#"

    Then execute backup.vbs with the kaseya variable written in it.

    You would download replace.vbs to the managed machine as part of the script.

    For more info on replace.vbs see:

    http://www.microsoft.com.nsatc.net/technet/scriptcenter/resources/qanda/feb05/hey0208.mspx

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: myArch-man