File tree Expand file tree Collapse file tree 4 files changed +35
-0
lines changed
Cmdlets/Write-Information Expand file tree Collapse file tree 4 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ task Test-1 {
3+ ($r = .\Test-1.ps1 )
4+ equals ($r -join ' |' ) ' ForEach-method|script-process|item 1|item 2|ForEach-Object|item 1|item 2'
5+ }
Original file line number Diff line number Diff line change 1+ # Write-Information writes nothing in ForEach method
2+
3+ For some reason (a bug?), ` Write-Information ` writes nothing in ` .ForEach({...}) ` method script blocks.
4+
5+ See [ Test-1.ps1] ( Test-1.ps1 ) . It shows the problem in ` .ForEach({...}) ` and
6+ also shows that ` Write-Information ` works fine in ` | .{process{...}} ` and `|
7+ ForEach-Object {...}` script blocks.
Original file line number Diff line number Diff line change 1+
2+ function test-me {
3+ [CmdletBinding ()]
4+ param ()
5+
6+ $items = 1 , 2
7+
8+ # KO, Write-Information writes nothing
9+ Write-Information ForEach - method
10+ $items.ForEach ({ Write-Information " item $_ " } )
11+
12+ # ok
13+ Write-Information script- process
14+ $items | .{process { Write-Information " item $_ " } }
15+
16+ # ok
17+ Write-Information ForEach-Object
18+ $items | ForEach-Object { Write-Information " item $_ " }
19+ }
20+
21+ test-me - InformationVariable iv
22+ $iv
Original file line number Diff line number Diff line change @@ -181,6 +181,7 @@ to their directory. See also [TESTS]. Some scripts require
181181- [ ` Wait-Process ` fails if a process name is not found] ( Cmdlets/Wait-Process )
182182- [ ` Where-Object ` ] ( Cmdlets/Where-Object )
183183- [ ` Write-Debug ` ] ( Cmdlets/Write-Debug )
184+ - [ Write-Information writes nothing in ForEach method] ( Cmdlets/Write-Information )
184185- [ ` Write-Progress ` ] ( Cmdlets/Write-Progress )
185186<!-- Cmdlets-->
186187
You can’t perform that action at this time.
0 commit comments