Write a script to check for a file and export the results to a CSV file
How can I use Automox to check if a certain file or version of a file exists, and then print those results to a .csv file?
First, you need a script that will check if the file exists (in the Remediation Code of the worklet). Then it writes the answer to the Activity Log in Automox. You can then create a report from Automox that checks to see where that policy was run, when, and then generate a CSV from those details.
Regarding the script, the Evaluation Code should be "exit 1", so it simply runs when it's told. But for the Remediation Code, you'll want something that will check for a file and then write something into the activity log so it can be printed out in a report. What you want it to say in the activity log is entirely up to you, but you'll need that worklet to say something to the Activity Log so you can verify if something is installed or not.
File Check
A good example that came from the Automox Community can be found here: https://community.automox.com/automox-92/check-for-file-655?postid=4754#post4754, which leads to here: https://community.automox.com/community-worklets-12/copy-a-file-to-a-folder-in-a-user-s-profile-659
The post contains this script which explains the basic premises of what you'll need:
# Check to see if the file exists in the user's profile location where it should be saved. If so, exit with no action.
if (Test-Path -Path "c:\Users\$currentusr\Downloads\$uploadfile") {
exit 0
} else { Exit 1 }
If you need another example, you can find one here: https://community.automox.com/community-worklets-12/worklet-get-hard-drive-free-space-percentage-1359
If (Test-Path "$env:allusersprofile\SoftwareDistribution")
{
Exit 0
}
Else {
Exit 1
}
Writing to the Activity Log
You can use things like Write-Output, or even just the error codes when writing to the Activity Log. Here is a script blocked example that you can adapt for to use in a script:
$scriptblock = {
(Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" | Get-ItemProperty | Where-Object {($_.DisplayName -like "Microsoft Update Health Tools")}).PSChildName
}
$runScriptBlock = & "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $scriptblock
Write-Host $runScriptBlock
When referring to the second half of the example, specifically ($runScriptBlock) takes the results and puts them in the Activity Log.
Once the script is completed, tested, and ready for execution in a worklet, run that worklet on the machines and devices that you need. Then, you can generate a report.
Generating a Report
In the console, go to Reports > Activity Log, then select the Policy Type (in this case, Worklets) and the Policy Name (whichever name was given to this worklet). This will give a report of all of the devices that the worklet ran on. To see more, you can click Expand all log details. Once your results are narrowed down, just press the Export to CSV option and that will give you the report!