与Powershell IDE相比,Powershell.exe中的结果不同
知道为什么会这样吗?我正在尝试构建一个包含我想要的所有信息的字符串(最终是在GUI、DataGridView单元格中输出),在Powershell.exe中,mediatype和healthstatus显示为代码(3,4,0),而不是IDE中显示的字符串(HDD、SSD、OK): 这两种代码完全相同:与Powershell IDE相比,Powershell.exe中的结果不同,powershell,ide,difference,Powershell,Ide,Difference,知道为什么会这样吗?我正在尝试构建一个包含我想要的所有信息的字符串(最终是在GUI、DataGridView单元格中输出),在Powershell.exe中,mediatype和healthstatus显示为代码(3,4,0),而不是IDE中显示的字符串(HDD、SSD、OK): 这两种代码完全相同: $DisquesPhysiques = invoke-command -ComputerName XXXX -ScriptBlock {get-physicaldisk} foreach ($d
$DisquesPhysiques = invoke-command -ComputerName XXXX -ScriptBlock {get-physicaldisk}
foreach ($disque in $DisquesPhysiques) {
$infodisque = $($disque.FriendlyName) + " - " + $($disque.SerialNumber)+ " - " + $($disque.MediaType)+ " - " + $($disque.HealthStatus)+ " - " + $([math]::Round($disque.Size/1gb)) + " GB"
$infodisque
}
最奇怪的是,有时它不会显示代码,而会显示实际单词(SDD、HDD、Health)。这是非常有问题的,因为我不能依赖它是一个数字或一个字一贯 这非常奇怪,因此我最终从CIM(WMI)获取信息,并对媒体类型(4是SDD)执行IF:
这非常奇怪,因此我最终从CIM(WMI)获取信息,并对媒体类型(4是SDD)执行IF:
$DisquesPhysiques = Get-CimInstance -ComputerName $poste MSFT_PhysicalDisk -Namespace Root\Microsoft\Windows\Storage
foreach ($disque in $DisquesPhysiques)
{
if ($disque.MediaType -eq 4) { $type = "SSD" }
else { $type = "HDD" }
$infodisque = $($disque.FriendlyName) + " - " + $($disque.SerialNumber) + " - " + $type + " - " + $([math]::Round($disque.Size/1gb)) + " GB"
$tableInfoPoste.Rows.add("Disque physique", $infodisque)
}