如何 return PowerShell 中此 WMIObject 的单个整数(温度)
How to return a single integer from this WMIObject in PowerShell (Temperature)
$temps = Get-CIMInstance MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"
$temps | Select-Object -Property InstanceName,@{n="TempF";e={(($_.currenttemperature /10 -273.15) *1.8 +32)}}
我似乎无法像往常一样 select-object -ExpandProperty 来获得 TempF 结果:
InstanceName TempF
------------ -----
ACPI\ThermalZone\THM__0 77.09
只要77.09
如果能显示摄氏度加分:)
$tempt = Get-CimInstance MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"
$tempF = ($tempt | Select-Object -Property InstanceName,@{n="TempF";e={(($_.currenttemperature /10 -273.15) *1.8 +32)}})|Select-Object -ExpandProperty TempF
顿悟,想通了
如果使用 powershell 3 或更高版本,您可以使用对象的成员名称调用 属性。
示例:
$temps.TempF
return 你的结果 77.09
$tempt = Get-CimInstance MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"
$temps = ($tempt | Select-Object -Property InstanceName,@{n="TempF";e={(($_.currenttemperature /10 -273.15) *1.8 +32)}},@{n="TempC";e={($_.currenttemperature /10 -273.15)}})
我还在 object/variable $temps
中添加了摄氏度。
您可以获得华氏度 $temps.tempF
或摄氏度 $temps.tempC
$temps = Get-CIMInstance MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"
$temps | Select-Object -Property InstanceName,@{n="TempF";e={(($_.currenttemperature /10 -273.15) *1.8 +32)}}
我似乎无法像往常一样 select-object -ExpandProperty 来获得 TempF 结果:
InstanceName TempF
------------ -----
ACPI\ThermalZone\THM__0 77.09
只要77.09
如果能显示摄氏度加分:)
$tempt = Get-CimInstance MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"
$tempF = ($tempt | Select-Object -Property InstanceName,@{n="TempF";e={(($_.currenttemperature /10 -273.15) *1.8 +32)}})|Select-Object -ExpandProperty TempF
顿悟,想通了
如果使用 powershell 3 或更高版本,您可以使用对象的成员名称调用 属性。
示例:
$temps.TempF
return 你的结果 77.09
$tempt = Get-CimInstance MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"
$temps = ($tempt | Select-Object -Property InstanceName,@{n="TempF";e={(($_.currenttemperature /10 -273.15) *1.8 +32)}},@{n="TempC";e={($_.currenttemperature /10 -273.15)}})
我还在 object/variable $temps
中添加了摄氏度。
您可以获得华氏度 $temps.tempF
或摄氏度 $temps.tempC