When creating a scriptblock for Register-ArgumentCompleter Faster Result using Object imbedded Where and ForEach
See original GitHub issueSummary of the new feature/enhancement
$wordToComplete* filter should always be used at the end of the scriptblock, otherwise you will give unexpected result to the user.
Another suggetion is to use object embeded Where and ForEach:
(
<your code>
).Where( {
$_.Name -like "$wordToComplete*"
}).ForEach( {
[System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name)
})
This will work faster than:
(
<your code>
) | Where-Object {
$_.Name -like "$wordToComplete*"
} | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name)
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Register-ArgumentCompleter (Microsoft.PowerShell.Core)
Within the script block, the first command retrieves all running services using the Where-Object cmdlet. The services are piped to the ForEach-Object cmdlet....
Read more >PowerShell | Argument completer not working when a file ...
cer extension when I press TAB button. Here is one of them $ArgumentCompleterCertPath = { Get-ChildItem | where-object { $_.extension - ...
Read more >Powershell | James O'Neill's Blog | Page 2 - WordPress.com
Moving the script block out of the call to Register-ArgumentCompleter and into a parameter attribute is simple enough, but it takes a bit ......
Read more >Improvements in ForEach and ForEach-Object
In PowerShell 7, both of these iteration methods are considerably faster. Using either ForEach ... Defining a long-running script block using ForEach-Object.
Read more >Is it possible to validate/autocomplete an input parameter ...
I'm trying to see if it's possible to write a powershell function that uses windows services as a validateset to tab autocomplete the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@B-Art, there are two options, which aren’t mutually exclusive:
If you feel the documentation is lacking / needs correction / a new topic should be created, open issues (and possible create PRs) at the documentation repo, https://github.com/MicrosoftDocs/PowerShell-Docs/issues (you can also create an issue direct from an existing online help topic to suggest a correction or improvement to it, specifically.
If you (possibly in addition) want to share PowerShell tips, use a forum such as Stack Overflow (you can ask a question that describes your scenario and then self-answer).
ForEach-Object
cmdlet vs. the.ForEach()
array method, and this answer shows use of the parameter-level[ArgumentCompleter()]
attribute.Other forums:
The Slack and Discord community chat forums (they seamlessly talk to each other).
The PowerShell.org forum for searching or posting questions about PowerShell.
Thanx again @mklement0