jobs/GetStats.ps1

Start-transcript C:\Program Files\PoSHServer\jobs\test.txt

#Read JSON From File
$JSON = Get-Content 'C:\Program Files\PoSHServer\webroot\http\data\uptime.json' | ConvertFrom-JSON

#Get A Count And Only Keep The Last 24 - Keeps a 24 Hour By Hour Record
$JSON = $JSON | Select -Last 23

#Create New Object From Current Stats
$NewStat = New-Object -Type PSObject -Property @{
    Date = $(Get-Date -F 'MMM-dd-yyyy HH:mm')
    CPU = $((Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average | Select Average).Average)
    RAM = $([math]::Round(100 - ($(Get-Ciminstance Win32_OperatingSystem).FreePhysicalMemory / $(Get-Ciminstance Win32_OperatingSystem).TotalVisibleMemorySize)*100,2))
}

#Add Object To Array
$JSON += $NewStat

#Write To File
$JSON | ConvertTo-JSON | Out-File 'C:\Program Files\PoSHServer\webroot\http\data\uptime.json'
Stop-transcript