Created
July 17, 2015 02:34
-
-
Save idlethreat/64e412f7ca46f8b4f949 to your computer and use it in GitHub Desktop.
Powershell Logging Loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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