[英]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.我创建了一个 powershell 脚本,以便将有关我的计算机硬件的信息发送到数据库。 Unfortunately, when I run my program I get these errors:
不幸的是,当我运行我的程序时,我收到了这些错误:
Impossible de convertir la valeur « HDDused : » en type « System.Double ».不可能转换为 valeur « HDDused : » en type « System.Double »。 Erreur : « Le format de la chaîne d'entrée est incorrect.
错误:« Le format de la chaîne d'entrée est 不正确。 » Au caractère D:\\projet\\new2.ps1:43 : 1
» 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.
谢谢。
You have several typos in your code, there is an e too much here:您的代码中有几个拼写错误,这里的e太多了:
$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. Get-NetAdapteer
已经被注释掉了,但是那个e也太多了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.