-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Update about_CommonParameters.md: Pipeline variable example #12392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Following a string of questions by a PowerShell learner, I realized that the `PipelineVariable` example in this document is counter-intuitive. So, I wrote a better one. I'll include the details in the PR message.
Following a series of questions by a PowerShell learner, I realized that the `PipelineVariable` example in this document is counter-intuitive. So, I wrote a better one. I'll include the details in the PR message.
Following a series of questions by a PowerShell learner, I realized that the `PipelineVariable` example in this document is counter-intuitive. So, I wrote a better one. I'll include the details in the PR message.
PoliCheck Scan ReportThe following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 issues. Other issues are also a high priority. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans. ✅ No issues foundMore information about PoliCheckInformation: PoliCheck | Severity Guidance | Term |
Learn Build status updates of commit 5add506: ✅ Validation status: passed
For more details, please refer to the build report. |
PoliCheck Scan ReportThe following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 issues. Other issues are also a high priority. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans. ✅ No issues foundMore information about PoliCheckInformation: PoliCheck | Severity Guidance | Term |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skycommand Thanks for the update and the thoughtful descriptions of your changes. It really helped me understand the motivation for the changes.
Learn Build status updates of commit f798a40: ✅ Validation status: passed
For more details, please refer to the build report. |
PR Summary
Following a series of questions by a PowerShell learner, I realized that the
PipelineVariable
example in this document is counterintuitive. So, I wrote a better one.Here are the questions:
Write-Host
andWrite-Output
commands in the example? Isn'tWrite-Host
supposed to be evil?Write-Host
orWrite-Output
?Here are my answers.
1: Why is the output different on my PC?
The output isn't different when you paste the original code into Windows Terminal, regardless of PowerShell's version. But if you:
&{
and}
...you get the following output, the last line of which poses a mental hurdle for a newbie. Examples are supposed to clarify, not befuddle.
Pasting the example into the prompt line of PowerShell 5.1 inside the Console Host generates a different result:
This is much better. Instead of a mysterious "temp" out of nowhere, we have a clear error message.
My solution: I used
Format-Table
and deliberately added empty lines. To be honest, though, I added the empty lines for readability. It wasn't until later when I discovered the effect they have on the Console Host.2: Why is the counter always -1 or 0?
To be honest, the OP didn't put the question in this precise fashion. It took me a while to understand the issue.
Firstly,
$_
is not the counter. It's the iterator. The PowerShell team has already recognized this concern a long time ago, and introduced$PSItem
.Secondly, there is a miscommunication. The output isn't saying "1 - $PSItem = 2". It is saying:
$Temp
equals 1$PSItem
equals 2My solution:
$PSItem
instead of$_
4 and 5:
Write-Host
vs.Write-Output
No,
Write-Host
isn't evil. But mixingWrite-Host
andWrite-Output
is bound to trigger unfathomable conditions, and here, we have one. Newbies don't immediately grasp thatWrite-Output
emits to pipeline, whileWrite-Host
writes directly to the screen device. Hence, the use ofWrite-Output
is counterintuitive.My solution:
Write-Information
to emit to screen.return
instead ofWrite-Output
to emit to pipeline.PR Checklist