在研究我需要的命令以获得答案所需的正确输出时,我花了几个小时试图弄清楚这一点,但无法确定为什么它没有按照应有的方式生成输出(在 PowerShell 5 和 7 中都会发生)。
返回的第一行格式不正确,但返回的输出的后续所有行均格式正确:
- 当前输出:
ForEach
||||Get-Disk
Get-Partition
Get-PSDrive
Write-Host
当直接复制终端输出时,问题变得更加令人困惑:PS $ # Match drive serial numbers to their drive letter mountpoints: $drive = (Get-PSDrive).Name -match '^[c-z]$' ""; Foreach ($letter in $drive) { Write-Host $letter': ' -nonewline Get-Partition -DriveLetter $letter | Get-Disk } C: Number Friendly Name Serial Number HealthStatus OperationalStatus Total Size Partition Style ------ ------------- ------------- ------------ ----------------- ---------- ---------- 3 Samsung SSD 850 EVO mSATA 1TB S*************V Healthy Online 931.51 GB GPT D: 0 Samsung SSD 870 EVO 4TB S*************H Healthy Online 3.64 TB GPT H: 1 Samsung SSD 870 EVO 4TB S*************R Healthy Online 3.64 TB GPT M: 0 Samsung SSD 870 EVO 4TB S*************H Healthy Online 3.64 TB GPT P: 0 Samsung SSD 870 EVO 4TB S*************H Healthy Online 3.64 TB GPT V: 3 Samsung SSD 850 EVO mSATA 1TB S*************V Healthy Online 931.51 GB GPT
C: Number Friendly Name Serial Number HealthStatus OperationalStatus Total Size Partition Style ------ ------------- ------------- ------------ ----------------- ---------- ----------3 Samsung SSD 850 EVO mSATA 1TB S*************V Healthy Online 931.51 GB GPT D: 0 Samsung SSD 870 EVO 4TB S*************H Healthy Online 3.64 TB GPT H: 1 Samsung SSD 870 EVO 4TB S*************R Healthy Online 3.64 TB GPT M: 0 Samsung SSD 870 EVO 4TB S*************H Healthy Online 3.64 TB GPT P: 0 Samsung SSD 870 EVO 4TB S*************H Healthy Online 3.64 TB GPT V: 3 Samsung SSD 850 EVO mSATA 1TB S*************V Healthy Online 931.51 GB GPT
- 预期输出:
Number Friendly Name Serial Number HealthStatus OperationalStatus Total Size Partition Style ------ ------------- ------------- ------------ ----------------- ---------- ---------- C: 3 Samsung SSD 850 EVO mSATA 1TB S*************V Healthy Online 931.51 GB GPT D: 0 Samsung SSD 870 EVO 4TB S*************H Healthy Online 3.64 TB GPT H: 1 Samsung SSD 870 EVO 4TB S*************R Healthy Online 3.64 TB GPT M: 0 Samsung SSD 870 EVO 4TB S*************H Healthy Online 3.64 TB GPT P: 0 Samsung SSD 870 EVO 4TB S*************H Healthy Online 3.64 TB GPT V: 3 Samsung SSD 850 EVO mSATA 1TB S*************V Healthy Online 931.51 GB GPT