Kaseya Community

Powershell to a custom field

  • I am trying to create an AP that runs a simple powershell command and then dump that info into a custom field.  Here is the command I am using.

    (Get-ChildItem 'c:\windows\System32\wuauclt.exe').versioninfo.productversion

    I am grabbing this information on the Windows Update Agent version so we can ensure we have the latest version installed.  Unfortunately, we still have users that have Windows 7.

    I have tried multiple ways to get this content populated into the custom field and have come up shortly.  I am specifically looking for the powershell portion of the script.

  • What we do for these cases is create a variable with the information you collect.

    After that you have options like print it to a text file on the system and read that information back into the custom field variable. Or you can do it all within the AP.

    $var = ((Get-ChildItem 'c:\windows\System32\wuauclt.exe').versioninfo.productversion)
    $var | Out-file -FilePath C:\Kaseya\wua.txt

    Here is a export of a portion of a procedure that collects the data from a txt file

    <Statement description="Load the content of the output file into variable" name="GetVariable" continueOnFail="true" osType="Windows">
    <Parameter xsi:type="EnumParameter" name="VariableType" value="FileContent"/>
    <Parameter xsi:type="StringParameter" name="SourceContent" value="#vAgentConfiguration.AgentTempDir#\wua.txt"/>
    <Parameter xsi:type="StringParameter" name="VariableName" value="WinBuild"/>

  • I use executePowershellCommand32BitSystem("",(Get-Item $filepath).VersionInfo.ProductVersion -as [version],true) followed by updateSystemInfo(customField, #global:psresult#).

    I put in some more error handling, formatting and logging, but ^ that's the main parts of getting a product verion into a custom field.

  • When populating the returned value, pay close attention to syntax... especially if your used to the CMD version of Execute to Global Variable.

    ExecuteShellCommandToVariable = #global:cmdresults#

    for PowerShell, its

    ExecutePowershell with "to Variable" = True outputs to #global:cmdresult# (NO S at the end)