Forum Discussion
Great question Matt
Specific to our use cases, we actually use LogicMonitor to run PowerShell scripts against our monitored systems. We are a small, vertical market MSP (about 400 customers, of which we wholly manage about 25% of them.) We set things that you'd normally push with group policies, such as Windows update configuration, folder redirection and the like. However, we push those settings directly into the registry on the monitored device. I've also used it to install and remove software. I also do temp file cleanup and various file system maintenance.
In all of these situations, I don't really have a need or want to run these processes more than once daily. I usually run it in the early AM, so at the top of my PowerShell script, I get the system time, then the entire rest of the script is contained in an if block that only runs if it matches the hour of the day that satisfies the if block. If it doesn't satisfy the if block, the script still exits gracefully with an exit code of 0.
I am not sure that I have fully answered your question though. I've posted an example of my script below for reference. I comment code quite a bit so that anyone behind me can hopefully decode my mess. That logic sort of goes along with using long variable names that are named for their exact function.
#gets the server name from LogicMonitor
$Server = $args[0]
#gets the current system date and time from the collector
$CurrentSystemDateTime = Get-Date
#if the current system time matches the hour in the if condition below, run the associated block of code
If ($CurrentSystemDateTime.Hour -eq '4')
{
Get-ChildItem "\\$server\C$\Windows\Temp\*" -Force -Recurse | Remove-Item -Force -Recurse -Confirm:$false #deletes all contents of C:\Windows\Temp on the monitored host, but leaves the temp folder in place
}
Related Content
- 2 years agoAnonymous