Skip to content

Instantly share code, notes, and snippets.

@Erik-H-zz
Created December 9, 2020 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Erik-H-zz/484c19b0d14347385b3ddf3cded5273e to your computer and use it in GitHub Desktop.
Save Erik-H-zz/484c19b0d14347385b3ddf3cded5273e to your computer and use it in GitHub Desktop.
Write Cpu and Memory to a Power BI Streaming dataset
$endpoint = "<<Your Endpoint comes here>>"
while($true)
{
$ComputerCPU = (Get-WmiObject -Class win32_processor -ErrorAction Stop | Measure-Object -Property LoadPercentage -Average | Select-Object Average).Average
$ComputerMemory = Get-WmiObject -Class win32_operatingsystem -ErrorAction Stop
$UsedMemory = $ComputerMemory.TotalVisibleMemorySize - $ComputerMemory.FreePhysicalMemory
$Memory = (($UsedMemory/ $ComputerMemory.TotalVisibleMemorySize)*100)
$RoundMemory = [math]::Round($Memory, 2)
$Date = Get-Date -DisplayHint Date -Format MM/dd/yyyy
$Time = Get-Date -DisplayHint Time -Format HH:mm:ss
#$RoundMemory
#$ComputerCPU
#$Date
#$Time
$payload = @{
"Date" =$Date
"Time" =$Time
"CPU" = $ComputerCPU
"Memory" = $RoundMemory
}
Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))
Write-Host "Date: " $Date " Time: " $Time " CPU: " $ComputerCPU " Memory: " $RoundMemory
sleep 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment