Does anyone have any good resources for how to write agent procedures.
I saw: http://community.kaseya.com/resources/m/knowexch/tags/Agent+Procedures/default.aspx on the Kaseya forum and I plan to look through it for useful scripts, but I am struggling to get simple commands: sfc /scannow or even small batch files/powershell scripts to execute properly within Kaseya.
Good Resources to learn more about agent procedures are: Kaseya Community Forum, Sample Procedures, some techjams (Webinars with technical information)
They used to have boot camps to demonstrate their product but I haven't seen any since 2010 -2011.
The first place to look at when an agent procedures fails is permissions and credentials. Most commands require either system or local Admin permissions to run. You can run commands as either "System" which is the default account used by the agent for most tasks, Logged on User or as the Agent Credentials account, if you put the "useCredential" step before the command you use to execute. You could also use the "ImpersonateUser" step however this locks your procedure down to a specific machine or domain.
I normally only use the original "executeShellCommand" and in some cases if needed the "executeFile" command the others are mostly derived from these two commands. Below are some example commands you can use to run PowerShell and VBscripts via the "executeShellCommand" commands;
powershell -command "& [FilePath]\[PowerShell Script Name] [Script Arguments]"
cscript.exe "[FilePath]\[Vbscript Script Name]" [Script Arguments]
The second most common problem is running 32bit commands on 64bit machines, it will sometimes work and sometimes it won't so its better to write your procedures work on either 32 or 64 bit machines. If you plan it right it will only take a few extra lines and you need to do this for working with the Registry anyways.
Common mistakes with executing Powershell via an agent procedure are;
- Permissions, some cmdlets can only be accessed by some accounts (Exchange cmdlets is a good example)
- right Cmdlets not loaded
- Powershell execution mode is to high (set as Unrestricted)
Other techniques to consider using is to always output your what you execute to a text/log file. You can also write the command you plan to execute to the Procedure Log so that you can you can debug it. This is a good way to find typos.