Skip to main content

Hi All,



im quite new to Automox and was wondering if you experts already collected best practices for creating worklets. For instance how can i write a proper output message to the activity log based on a step in evaluation or remediation and what things did you come up with when using the worklets?



At this point for me anything goes!

For output messages, you can only write to the activity log in the remediation section.



Anything you write to stdout will get added to the activity log if the remediation exit code is 0. Anything you write to stderr will get added to the activity log if the remediation exit code is not 0.



Welcome aboard and hope that helps!


Do you have an example? and can that be without mentioning exit 0 or 1 just like patches etc so the activity log is clean (autism in me)


Here’s an example that uses the Write-Output command to write success or failure messages to the Details column of the Activity Log:
 

 


This worklet will allow you to run the Windows Cleanup Tool on any of your Windows endpoints, based on the amount of free space remaining on the C: drive.
If you use the /SageSet and /SageRun commands, you’ll need to create presets on the endpoints first. This /SageSet process can be automated, as some folks have demonstrated here:


If you don’t want to bother with the /SageSet presets you can use the /VeryLowDisk flag instead, with the caveat that this will pop up the scan completion wind…

 

 

 

 

 

You do need to specify the exit code to tell Automox whether to grab the error output or the success output as it will only write one and not both.

 


and this wil only write the text or also the exit 1 or exit 0 to the activity log?


No it doesn’t write the exit 1 or the exit 0 - that’s just what the script returns to the console to indicate success or failure. Only what you explicitly specify using write-output is what will show in the Details column.


any idea why im getting this?



image



followed the code in the example;



{


Write-Output “Reboot Initiated”


exit 0}


Is that the totality of the remediation code block? In that case you can dispense with the curly brackets.



If not, post the whole of your code here so I can get a better sense of what is happening.


This is the whole code based on the reboot worklet



$sysInfo = New-Object -ComObject "Microsoft.Update.SystemInfo"

if($sysInfo.RebootRequired)

{

######################################################### Start Parameters - Editable #########################################################



#hardset the reboot countdown timer in seconds (e.g. 5400 for 90 minutes). After this time elapses reboot command is initiated. In this example it's 90 minutes

$rebootimer = 5400

#set the first notification message copy. Include the reboot time value set previously. In this example it's 90 minutes

$message1 = "We have installed security updates. Your device will automatically reboot within 90 minutes. Please save your work. Plukon IT Department"

#Define the time to wait until the second notification message is sent in seconds (e.g. 1800 for 30 minutes).

$message2wait = 1800

#set the second notification message copy. In this example 60 minutes.

$message2 = "We have installed security updates. Your device will automatically reboot within 60 minutes. Please save your work. Plukon IT Department"

#reset the reboot time to match the time indicated in the previous notification message copy (e.g. 3600 for 60 minutes)

$rebootimer2 = 3600

#Define the time to wait for the third notification message to launch in seconds (e.g. 1800 for 30 minutes). In this example it's 30 minutes

$message3wait = 1800

#set the third notification message copy. In this example 30 minutes.

$message3 = "We have installed security updates. Your device will automatically reboot within 30 minutes. Please save your work. Plukon IT Department"

#reset the reboot time to match the time indicated in the previois notification message copy (e.g.1800 for 30 minutes)

$rebootimer3 = 1800

#Define the time to wait for the final notification message to launch in seconds (e.g. 900 for 15 minutes). This needs to be in sync with when the reboot is scheduled.

#In this example it will warn the users 15 minutes before the reboot, so we set it to 900 (15 minutes)

$message4wait = 900

#set the final notification copy. The time for reboot should match the amount of time until the reboot take place

$message4 = "We have installed security updates. Your device will automatically reboot within 15 minutes. Please save your work. Plukon IT Department"

#reset the reboot time to match the time indicated in the previois notification message copy (e.g.900 for 15 minutes)

$rebootimer4 = 900



################################################################ End Parameters ################################################################





### Commands being run ###

shutdown /a

shutdown /r /t $rebootimer /d p:4:1 /c $message1

Start-Sleep -Seconds $message2wait

shutdown /a

shutdown /r /t $rebootimer2 /d p:4:1 /c $message2

Start-Sleep -Seconds $message3wait

shutdown /a

shutdown /r /t $rebootimer3 /d p:4:1 /c $message3

Start-Sleep -Seconds $message4wait

shutdown /a

shutdown /r /t $rebootimer4 /d p:4:1 /c $message4

}

{

Write-Output "Reboot Initiated"

exit 0}

Thanks, I’ll test that out today and see if I can reproduce the behavior, and if so, let you know how to make it work properly.


So sorry for the delay in getting back to you on this one. It’s been one heck of a week.



Anyway, it was as I suspected, that the curly brackets around the last two commands was causing the issue. After I removed those I just see “Reboot Initiated” in the Details section.


Reply