Powershell `在`foreach`集合表达式中写入输出`

Powershell `在`foreach`集合表达式中写入输出`,powershell,Powershell,实际上,我正在浏览Bruce Payette的《Powershell in Action》,找到了一段我实际上不懂的代码片段 $characterData = @{ 'Linus' = @{ age = 8; human = $true} 'Lucy' = @{ age = 8; human = $true} 'Snoopy' = @{ age = 2; human

实际上,我正在浏览Bruce Payette的《Powershell in Action》,找到了一段我实际上不懂的代码片段

$characterData = @{                                                     
    'Linus' = @{ age = 8; human = $true}
    'Lucy' = @{ age = 8; human = $true}
    'Snoopy' = @{ age = 2; human = $true}
  }
  
  function Get-Character ($name = '*')
  {
    foreach ($entry in $characterData.GetEnumerator() | Write-Output)     
    {
      if ($entry.Key -like $name)
      {
          $properties = @{ 'Name' = $entry.Key } +                        
            $entry.Value
          New-Object PSCustomObject -Property $properties                 
       }
    }
  }

我的问题是,我不明白为什么在
foreach($characterData.GetEnumerator()| Write Output)中使用
Write Output
?此语法是否可以解释为等效于
$characterData.GetEnumerator()| ForEach对象{…


Thx

W-O
是完全不需要的。你可以完全移除管道和
W-O
调用,代码仍然有效。因为努努人的大脑将史努比列为人类……我猜代码的作者是智障。[咧嘴笑]鉴于这一点,我假设是某种教程(?),写输出可能只是为了告诉你发生了什么。我在调试时做了类似的事情。@怀疑论者
Write Output
没有显示任何内容,这是完全多余的。
W-O
是完全不需要的。你可以完全移除管道和
W-O
调用,代码仍然工作。因为NUNUU br我把史努比列为人类……我猜代码的作者是智障。[咧嘴笑]鉴于这是某种教程(?),写输出可能只是为了告诉你发生了什么。我在调试时也会做类似的事情。@怀疑论者
写输出
没有显示任何内容,这完全是多余的。