Select-String tem% co_de parâmetro% para este propósito:
Return only the first match in each input file.
By default, Select-String returns a MatchInfo object for each match found.
- ss64.com
Você pode usá-lo assim:
gci -Recurse | sls -List FOOBAR
Veja como alguns resultados de amostra se parecem (pesquisando o SDK do Windows em -List
):
shared\bthdef.h:576:#define BTH_ERROR(_btStatus) ((_btStatus) != BTH_ERROR_SUCCESS)
shared\netioapi.h:2254: ERROR_SUCCESS on success. WIN32 error code on error.
shared\rpcnterr.h:34:#define RPC_S_OK ERROR_SUCCESS
shared\winerror.h:214:// MessageId: ERROR_SUCCESS
um\advpub.h:40:// ERROR_SUCCESS_REBOOT_REQUIRED Reboot required.
um\bluetoothapis.h:243:// ERROR_SUCCESS
um\ClusApi.h:571:_Success_(return == ERROR_SUCCESS)
um\dsparse.h:102:_Success_(return == ERROR_SUCCESS)
um\eapmethodpeerapis.h:228:// If the function succeeds, it returns ERROR_SUCCESS. Otherwise, it is
um\eappapis.h:56:// If the functions succeed, they return ERROR_SUCCESS. Otherwise, it is
um\MapiUnicodeHelp.h:583: if ((hkeyPolicy && RegQueryValueExW(hkeyPolicy, szName, 0, &dwType, (LPBYTE)
&dwLcid, &dwSize) == ERROR_SUCCESS && dwType == REG_DWORD) ||
um\Mddefw.h:127: routine will return ERROR_SUCCESS and the inherited data even if
um\Msi.h:1693:// Returns ERROR_SUCCESS if file is a package.
um\MsiQuery.h:192:// Returns ERROR_SUCCESS if successful, and the view handle is returned,
um\msports.h:46: ERROR_SUCCESS if the dialog was shown
um\ncryptprotect.h:164: ERROR_SUCCESS
um\NTMSAPI.h:1761:_Success_ (return == ERROR_SUCCESS)
um\oemupgex.h:108:// Returns: ERROR_SUCCESS in case of success, win32 error otherwise
um\PatchWiz.h:90:// ERROR_SUCCESS, plus ERROR_PCW_* that are listed in constants.h.
um\Pdh.h:415:_Success_(return == ERROR_SUCCESS)
Se você quiser recuperar os objetos ERROR_SUCCESS
reais (em vez do caminho relativo e de um único resultado de correspondência), use-o da seguinte forma:
Get-ChildItem -Recurse -File | where { Select-String -Path $_ -List -Pattern FOOBAR }