How to count objects in PowerShell?

后端 未结 5 2179
星月不相逢
星月不相逢 2020-12-07 14:17

As I\'m reading in the PowerShell user guide, one of the core PowerShell concepts is that commands accept and return objects instead of text. So for example, runnin

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 14:51

    @($output).Count does not always produce correct results. I used the ($output | Measure).Count method.

    I found this with VMware Get-VmQuestion cmdlet:

    $output = Get-VmQuestion -VM vm1
    @($output).Count
    

    The answer it gave is one, whereas

    $output
    

    produced no output (the correct answer was 0 as produced with the Measure method).

    This only seemed to be the case with 0 and 1. Anything above 1 was correct with limited testing.

提交回复
热议问题