question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with "get-help select-string"

See original GitHub issue

Prerequisites

Steps to reproduce

In Powershell Core 7.2.6 on Windows 11, type “get-help select-string” command and press enter.

Expected behavior

The help of the command select-string

Actual behavior

It doesn't show me the help but a bunch of characters, which I think mean languages and countries.

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.6
PSEdition                      Core
GitCommitId                    7.2.6
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

WindowsTerminal_bPG0ZwLpXk

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jhoneillcommented, Aug 19, 2022

You are getting the correct text when the help file for Select-string is absent.

What happens with no help file, is Get-Help looks at the command’s parameter-sets and for each one it builds a block under “syntax”. Then for each parameter it looks to see what type it is, and if it has prescribed values in a validateSet or an enum. The screen shot shows it works through -Pattern and -Path before it gets to -culture, and it will have -SimpleMatch -CaseSensitive etc after that. As @MartinGC94 says there is a LOT in the validate set for -culture, and Get-Help inserts the equivalent of

"{" +( (Get-Command Select-String).parameters["culture"].attributes[1].validvalues -join " | ") + "}"

And repeats it for each of the six parameter sets which have a -culture parameter. So we get a lot, six times over.

The default help text should end

REMARKS
    Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
        -- To download and install Help files for the module that includes this cmdlet, use Update-Help.

So the primary fix is to install help. But in in some situations that’s not an option (e.g. PowerShell installed from a private repo on a server without internet access). As @dkaszews says stopping the list after a certain number of items might be smarter. They can be stopped at source by putting something into https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/help/DefaultCommandHelpObjectBuilder.cs (see from line 251 to 348 ) that limits the number of values from an enum or validate set. But if someone creates a help file with a stupid number of parameter values in a parameter value group, they will still be displayed. Maybe we want to honour what is in file on all occasions, but if not the change can be made at output time. I’m not sure where it stored in pwsh, but the formatting for Windows PowerShell is defined by C:\Windows\System32\WindowsPowerShell\v1.0\Help.format.ps1xml - in that file its line 212 which builds the output with

 " {$($_.ParameterValueGroup.ParameterValue -join ' | ')}"

It would be fairly easy (I think) to make that $_.ParameterValueGroup.ParameterValue[0..20] and get only the first 20 values.

If people think either option is worthwhile, a new issue can be opened asking for that. (Upvote this comment enough and I’ll do it!)

<div> GitHub</div><div>PowerShell/DefaultCommandHelpObjectBuilder.cs at master · PowerShell/PowerShell</div><div>PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.</div>
0reactions
dkaszewscommented, Aug 21, 2022

@jhoneill I don’t see a benefit in skipping the if statement, as depending on how efficient PowerShell implementation of regex is, you may waste a lot of time running complicated replacements just to do nothing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Select-String (Microsoft.PowerShell.Utility)
The Select-String cmdlet uses regular expression matching to search for text patterns in input strings and files. You can use Select-String similar to...
Read more >
Select-String doesn't do what you think it does : r/PowerShell
Get-Help Select-String -Parameter SimpleMatch. Indicates that the cmdlet uses a simple match rather than a regular expression match.
Read more >
How to Access Powershell Select-String Return Values
NET data type(s) of the objects output by that cmdlet. To see this section locally, you must invoke Get-Help with the -Full switch,...
Read more >
Select-String. How to use multiple pattern conditions?
Hello,. I am trying to parse through a log file searching for lines that contain strings. The below scripts works to pull all...
Read more >
Powershell: Search for String or grep ...
The Select-String cmdlet searches for text and text patterns in input strings and files. You can use Select-String similar to grep in UNIX...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found