-
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 |
sdwheeler
left a comment
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
PipelineVariableexample in this document is counterintuitive. So, I wrote a better one.Here are the questions:
Write-HostandWrite-Outputcommands in the example? Isn'tWrite-Hostsupposed to be evil?Write-HostorWrite-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-Tableand 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:
$Tempequals 1$PSItemequals 2My solution:
$PSIteminstead of$_4 and 5:
Write-Hostvs.Write-OutputNo,
Write-Hostisn't evil. But mixingWrite-HostandWrite-Outputis bound to trigger unfathomable conditions, and here, we have one. Newbies don't immediately grasp thatWrite-Outputemits to pipeline, whileWrite-Hostwrites directly to the screen device. Hence, the use ofWrite-Outputis counterintuitive.My solution:
Write-Informationto emit to screen.returninstead ofWrite-Outputto emit to pipeline.PR Checklist