Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
与Powershell IDE相比,Powershell.exe中的结果不同_Powershell_Ide_Difference - Fatal编程技术网

与Powershell IDE相比,Powershell.exe中的结果不同

与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

知道为什么会这样吗?我正在尝试构建一个包含我想要的所有信息的字符串(最终是在GUI、DataGridView单元格中输出),在Powershell.exe中,mediatype和healthstatus显示为代码(3,4,0),而不是IDE中显示的字符串(HDD、SSD、OK):

这两种代码完全相同:

$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)
                }