0

I wish Get-Help showed the -Detailed information by default and had paged output. I wrote a function called "Help" to do that, but it doesn't handle parameters beyond the cmdlet to get help about. I was hoping splatting would work to pass-through the extra parameters, but it doesn't. Here's my naive attempt:

function Help { Get-Help -Detailed @args | less}

It works fine if you just call it with one parameter, like help Get-ChildItem, but if you call with more, like help Get-ChildItem -Parameter Path it gives an error:

Get-Help : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:17
+ function Help { Get-Help -Detailed @args | less}
+                 ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-Help], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.GetHelpCommand

Does anyone know if there's a way to do this that's not terribly ugly?

I noticed this and this similar answers, but they don't work for the case above.

Community
  • 1
  • 1
Vimes
  • 10,577
  • 17
  • 66
  • 86
  • By "paged output", do you mean the "more" feature? If so, you should know that the more feature works differently in the Powershell ISE than it does in the Console host. The reason, as far as I can tell, is that the ISE does not set up the window size the way the console host does. – Walter Mitty Mar 22 '15 at 07:24
  • Yes, the More feature. Only I'm using Less instead because... I don't remember exactly now but it's more fully featured. I think it lets you scroll up and some other neat things. I had stumbled on the ISE issue you mentioned. It's too bad. – Vimes Mar 22 '15 at 21:09

2 Answers2

1

Assuming that you use PowerShell V3+, you can do that:

$PSDefaultParameterValues['Get-Help:Detailed']=$true

and use build in Help function, which has screen paging (to use Less instead of More for paging, run New-Alias more less).

Vimes
  • 10,577
  • 17
  • 66
  • 86
user4003407
  • 21,204
  • 4
  • 50
  • 60
  • I like this. If only there were a way to implicitly pipe to Less. – Vimes Mar 22 '15 at 21:16
  • @JVimes You can do that `New-Alias more less`, and build-in function `Help` will use `less` instead of `more`. – user4003407 Mar 23 '15 at 04:09
  • I totally didn't realize Help was a whole other function, with screen paging. I thought it was just an alias. In that case, this is just what I wanted. Thanks! – Vimes Mar 23 '15 at 16:01
1

What you want is a Proxy Function.

Generally this requires re-creating all of the parameters in the original command in the proxy function. I haven't used it, but this script posted in the script repository that's supposed to help make that less tedious.

mjolinor
  • 66,130
  • 7
  • 114
  • 135
  • I was afraid it'd be something like that. At least it should get tab completion for parameters, which my solution doesn't have. I might stick with mine for now, and just type it all out when I need to. But it's good to be aware of proxy functions. – Vimes Mar 22 '15 at 21:19
  • Update: Since I'm using v3+, PetSerAl's solution worked better. But this should be the answer for v1 and 2. – Vimes Mar 23 '15 at 15:56
  • I didn't propose that as a solution because it didn't satisfy your requirement of having the output also piped through less in the bargain. – mjolinor Mar 23 '15 at 17:06
  • I didn't think so, either, but it turns out PowerShell's built-in Help command is a proxy function that already pipes to More. I didn't realize that until today (thought it was just an alias). – Vimes Mar 23 '15 at 17:27
  • Link is dead. Here's working link: https://devblogs.microsoft.com/scripting/proxy-functions-spice-up-your-powershell-core-cmdlets/ – Applejag Apr 27 '20 at 08:51