In this section we show a PowerShell example to do the exact same thing as with a REST client shown in this section. In the example we will use the actual CPU value and the current timestamp (in UTC). The code has a simple while-statement that will sample the CPU four times per minute.
$user = "username"
$pass = "Password"
$pair = "${user}:${pass}"
While ($true) {
$cpu = Get-WmiObject win32_processor | select LoadPercentage
$cpu1 = $cpu.loadpercentage
$TimeNow = Get-Date
$time = $TimeNow.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss") + "Z"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$JSON = @"
[{
"nodeRef": {
"nodeType": "aims.int-sys.server",
"parts": {
"part1": "part1value"
}
},
"statType": "aims.int-sys.server-cpu",
"time": "$time",
"value": "$cpu1"
}]
"@
Invoke-WebRequest -Uri "https://api.aimsinnovation.com/api/environments/{environmentId}/statpoints/" -Method:Post -Headers @{"Authorization"=$basicAuthValue; "X-System"="10"} -Body $JSON -ContentType "application/json" -ErrorAction:Stop -TimeoutSec 60
sleep 15
}
