user13774090
user13774090

Reputation:

Send information about hardware of my computer to a database

I created a powershell script in order to send information about my computer hardware to a database. Unfortunately, when I run my program I get these errors:

Impossible de convertir la valeur « HDDused : » en type « System.Double ». Erreur : « Le format de la chaîne d'entrée est incorrect. » Au caractère D:\projet\new2.ps1:43 : 1

My code is :

function Get-Temperature {
    $t = Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"
    $returntemp = @()

    foreach ($temp in $t.CurrentTemperature)
    {
        $currentTempKkelvin = $temp / 10
        $currentTempCelsius = $currentTempKelvin
        $reeturntemp = $currentTempCelsius
    }
    return $returntemp 
}

#Get-Counter -Counter "\GPU Engine(*)\Utilization Percentage"

$CpuTemp = Get-Temperature
$CpuTemp = $cpuTemp -as [float]
"CpuTemp : " + $CpuTemp

$CpuUsage = Get-Counter -Counter "\Processeur(_total)\% temps processeur" | ForEach-Object {$_.CounterSamples[0].CookedValue}
$CpuUsage = $CpuUsage -as [float]
"CpuUsage : " + $CpuUsage

$TotalMemoire = Get-CimInstance Win32_PhysicalMemory |  Measure-Object -Property capacity -Sum | Foreach {"{0:N2}" -f ([math]::round(($_.Sum / 1GB),2))}
$TotalMemoire = ($TotalMemoire -as [float])/100
#$TotalMemoire

$RAMfree =  Get-Counter -Counter "\Mémoire\Octets disponibles" | ForEach-Object {$_.CounterSamples[0].CookedValue}
$RAMfree = ($RAMfree -as [float])/1E+09
"RAMfree : " + $RAMfree 

$RAMused = ($TotalMemoire - $RAMfree)
"RAMused : " + $RAMused

$HDDfree = Get-Counter -Counter "\Disque logique(C:)\Mégaoctets libres" | ForEach-Object {$_.CounterSamples[0].CookedValue}
$HDDfree = ($HDDfree -as [float])/1000
"HDDfree : " + $HDDfree

$HDDused = Get-PSDrive C | ForEach-Object {$_.Used}
$HDDused = ($HDDused -as [float])/1E+09
"HDDused : " - $HDDused

#$AddMac = Get-NetAdapteer | ? { $_.name -eq ""ethernet" } | Select-0bject -ExpandProperty macaddress
#"Adresse MAC : " + $AddMac

$cpuApp = 0
$cpuTemp = 0
$cpuUsage = 0

$infos = @{
CpuTemp = $CpuTemp
CpuUsage = $CpuUsage
CpuApp = $CpuApp
RAMfree = $RAMfree
RAMused = $RAMused
HDDfree = $HDDfree
HDDused = $HDDused
CguTemp = $CguTemp
CguUsage = $CguUsage
#AddMac = $AddMac
}

Invoke-WebRequest -URI 'http://172.31.6.204/elle/public/login' -Method POST -Body $infos

Can you help me please ? Thanks.

Upvotes: 0

Views: 91

Answers (1)

Palle Due
Palle Due

Reputation: 6312

You have several typos in your code, there is an e too much here:

$ree!turntemp = $currentTempCelsius

And what's the point of iterating through the temperatures when you only use the last one? But the thing that is complained about is:

"HDDused : " - $HDDused

You are subtracting a number from a string instead of doing string concatenation. Use a plus as you do the other places.

Get-NetAdapteer has been commented away, but that also has an e too much.

Upvotes: 1

Related Questions