Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the PowerShell "Search" verb for?

Tags:

powershell

The MSDN page "Approved Verbs for Windows PowerShell Commands" says:

The Find verb is used to look for an object. The Search verb is used to create a reference to a resource in a container.

What does "create a reference to a resource in a container" mean? Does it mean defining a new name for an existing resource? Does it mean taking some information about a resource and converting that information into a reference? Or does it mean something else?

What's an example of how the "Search" verb is intended to be used? And what does this action have to do with searching?

like image 835
Tanner Swett Avatar asked Aug 26 '16 19:08

Tanner Swett


1 Answers

tl;dr

  • The distinction between Search and Find is ill-defined in the realm of PowerShell.

  • Existing, Microsoft-originated modules reflect this confusion, arbitrarily coming with either Find-* or Search-* cmdlets, but not both.

  • To resolve this, ask Microsoft for clarification, which can result in either :

    • a useful distinction between Search and Find that needs to be explained and can then guide future implementations.
    • or declaring one verb a (legacy) synonym of the other, and making a recommendation to only use one going forward.

Human language is ambiguous, which is invariably at odds with PowerShell's commendable quest for consistency, as documented in Approved Verbs for Windows PowerShell Commands.

Regrettably, that document itself contains many ill-defined terms (as of this writing), used vaguely interchangeably, such as resource, object, item, target, and reference.

Somewhat ironically, the document admonishes:

To enforce consistency across cmdlets, do not use a synonym of an approved verb.

Arguably, in English find and search ARE synonyms, with only the degree of certainty about the outcome distinguishing them: search is more open-ended than find: you may search without result, but to find implies a successful outcome.

Is this distinction worth making when it comes to naming cmdlets?

Arguably not, which is reflected in real-world Microsoft implementations - such as the Active Directory, Exchange, and PowerShellGet modules - choosing one term to the exclusion of the other.

Again, somewhat ironically, said document seems to reverse the human-language relationship between find and search:

  • Find

Looks for an object in a container that is unknown, implied, optional, or specified.

  • Search

Creates a reference to a resource in a container.

Leaving aside the ambiguity around object vs. container (and what a reference is in this context), it is the Find definition here that sounds more open-ended than Search - in opposition to human language (English).


felixfbecker observes the following with respect to the noun part of Search-* and Find-* cmdlets:

I think another difference is that the noun in Search-Noun describes what is searched [the search space] while the noun in Find-Noun describes what is being searched for [the kind of item]. Therefore, e.g., a cmdlet Search-Wikipedia makes sense, whereas Find-Wikipedia does not. Find-WikipediaArticle and Search-Wikipedia-Article, on the other hand, both make sense, but mean different things.

like image 120
mklement0 Avatar answered Oct 05 '22 10:10

mklement0