Skip to content

Instantly share code, notes, and snippets.

@idlethreat
Created July 17, 2015 02:34
Show Gist options
  • Save idlethreat/64e412f7ca46f8b4f949 to your computer and use it in GitHub Desktop.
Save idlethreat/64e412f7ca46f8b4f949 to your computer and use it in GitHub Desktop.
Powershell Logging Loop
# Implement FreePhysicalMemory log item, if necessary. This runs once.
try
{
# create a new event log type of "FreePhysicalMemory"
[System.Diagnostics.EventLog]::CreateEventSource("FreePhysicalMemory", "System")
}
catch
{
# ignore if the above fails.
}
# now, it's time for our endless loop...
while($true)
{
# pause the script from running for 60 seconds...
Start-Sleep -s 60
$myFreeMemory = (Get-WmiObject Win32_OperatingSystem).FreePhysicalMemory
# for debugging purposes. comment out when happy
"my free memory -> $myFreeMemory"
# logging entries for graylog
write-eventlog -logname System -source FreePhysicalMemory -eventID 6670 -entrytype Information -message "$myFreeMemory" -category 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment