I've written a script in Powershell showing the performance of the computer.
If I want to import the file via js, comes an error like: Uncaught SyntaxError: Unexpected token
I've tried much things, changed the output parameta 3 times and created psobjects nothing worked...
My Code:
<#
Project: Statistik-Dashboard
Class: Get-Value
created by Nicolai
#>
#Disks
$ComuterSystem = Get-CimInstance -ClassName Win32_ComputerSystem
$storage = foreach ($Computer in $ComuterSystem) {
$LogicalDisk = Get-CimInstance -ClassName win32_logicaldisk -ComputerName $ComuterSystem.Name
$diskHash = @{}
foreach ($disk in ($LogicalDisk | ? {$null -ne $_.DeviceId})) {
$diskHash.Add($disk.DeviceID, $disk.Size)
}
[PSCustomObject]@{
Name = $Computer.Name
Model = $Computer.Model
Manufacturer = $Computer.Manufacturer
LogicalDisk = $LogicalDisk
Disks = $diskHash
Selection = $LogicalDisk | Select-Object DeviceID, VolumeName, Size, FreeSpace
}
}
$disksum = $diskHash.count
$platte = (Get-PhysicalDisk)
$ssds = (Get-PhysicalDisk | ? model -Match 'ssd')
$ssdsum = 0
foreach($platte in $ssds) {
$ssdsum++
}
#RAM
$ram_freephysical=0
$ram_totalvisible=0
$ram_freephysical=Get-WmiObject Win32_OperatingSystem | fl *freePhysical* | Out-String
$ram_totalvisible=Get-WmiObject Win32_OperatingSystem | fl *totalvisiblememory* | Out-String
$ram_freephysical = $ram_freephysical -replace '\D+(\d+)','$1'
$ram_totalvisible = $ram_totalvisible -replace '\D+(\d+)','$1'
$ram = $ram_totalvisible - $ram_freephysical
$ram = [math]::Round($ram/$ram_totalvisible*10000)/100
#CPU
$cpu = (Get-WmiObject win32_processor | Measure-Object -Property LoadPercentage -Average | Select Average).Average
#Ojects
$Diskinfo = [PSCustomObject]@{
CPUusage = $cpu
RAMusage = $ram
}
$Utilization = [PSCustomObject]@{
SSDsum = $ssdsum
HDDsum = $hddsum
Disksum = $disksum
}
$disks = [ordered]@{}
for ($i=1; $i -le $storage.Selection.Count; $i++) {
$disks["Disk${i}"] = $storage.Selection[$i-1]
}
#collector
$stats = [ordered]@{
Utilization = $Utilization
Diskinfo = $Diskinfo
$Computer.Name = $disks
}
#convertor
$file = "C:\Temp\$($ComuterSystem.Name).json"
ConvertTo-Json @($stats) | Add-Content -Path $file
The output of the convert:
{
"Utilization": {
"SSDsum": 2,
"HDDsum": 1,
"Disksum": 6
},
"Diskinfo": {
"CPUusage": 8,
"RAMusage": 81.84
},
"W10-NICO": {
"Disk1": {
"DeviceID": "C:",
"VolumeName": "System",
"Size": 63020462080,
"FreeSpace": 31977562112
},
"Disk2": {
"DeviceID": "D:",
"VolumeName": null,
"Size": null,
"FreeSpace": null
},
"Disk3": {
"DeviceID": "F:",
"VolumeName": "Daten",
"Size": 499529019392,
"FreeSpace": 480264626176
},
"Disk4": {
"DeviceID": "G:",
"VolumeName": "SSD",
"Size": 63020462080,
"FreeSpace": 62914928640
},
"Disk5": {
"DeviceID": "H:",
"VolumeName": "System",
"Size": 106779635712,
"FreeSpace": 70762377216
},
"Disk6": {
"DeviceID": "U:",
"VolumeName": "System",
"Size": 106779635712,
"FreeSpace": 70762377216
}
}
}
I hope somebody can help me :)