Skip to content

Commit 57133d2

Browse files
committed
Add Cmdlets/Write-Information
1 parent dae2d57 commit 57133d2

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)