2

In doing some research on another question, I wanted to check to be sure that tree was not an actual native PowerShell command or alias. Of course, the proper way to do this is with Get-Command. However, when I'm looking up a command I'm not sure of, I usually prefer to go straight to the help file if it exists instead of doing a two-step of "check if the command exists, then go to help". So, the command I ran was help tree. To my surprise, it returned the help file for Copy-Item!

As a sanity check, I spelled it out - Get-Help tree - but ended up with the same results. To see if tree was, for some odd reason, an alias for Copy-Item I ran gal tree - this returned an error saying such alias does not exist. I ran gal -def Copy-Item to check all aliases for Copy-Item, and it only pulled up copy, cp, and cpi.

Finally, I did gcm tree to see what PowerShell was actually supposed to be using for tree. This turned up, as I expected, a CommandType of "Application" with Definition "C:\Windows\system32\tree.com".

Unfortunately, none of this answers for the unusual behavior of Get-Help here. Why would Get-Help tree return the help file for Copy-Item, when the two appear entirely unrelated? This behavior has been duplicated in PowerShell 2.0 on Windows 7 SP1, and PowerShell 4.0 on Windows 8.1.

enter image description here

Iszi
  • 14,163

1 Answers1

0

You are getting this result because the help for Copy-Item is the only help file in your system that contains the keyword "tree". The following command will show that the string "tree" occurs in the remarks of the examples section.

(Get-Help -Name Copy-Item).examples.example.remarks | Where-Object { $_ -match 'tree'}

Try the below command and you'll find that the keyword "intact" is unique to that help file too.

Get-Help intact

This also explains that it is not found using another locale.

For example, for a list of help files containing the keyword "particular", use the command

Get-Help particular

I hope this clarifies the usage.

MFT
  • 723