I'm looking to identify all files from text file of paths that match a pattern. Select-String
is searching the content of the files and not just the list of file names. How do I confine it to just the list?
I've read through the docs on SS64 and Microsoft and tried the parameters that look related,-Raw
, -SimpleMatch
and -Path
for instance. No go.
List of names to search through:
» $fileList
\\server\imagery\09Aug2015\506000_6717000.tif
\\server\imagery\515000_6896000.tif
The results I'm getting:
» Select-String -Pattern "Aug" $fileList
\\server\imagery\516000_6895000.tif:8675:�|K`�����aug♦b��k��!���1�]��4hl�
\\server\imagery\516000_6895000.tif:25187:�c;H�S�m�EFyѰ��p9犞��`��!♂5�6"�_���F9�↨��Y�w↑��h�►�,�(↔
���%�]�ֶ� ↨↕�}zd��Z-������K��E@ �♦��V~�☼�5[kw���Ȩ‼=�����^��|e▲�¶�X�푆NH,��v�∟�[⌂♀x�/☼�s$�[ZF�;g♀�8�k������cǑxz��W���"���3.♠ ~��
�→Ѷ��'��↑�V#���[D�$6� ↑�/�0��W#���q�§�*��u �♦��▬�v↔☺��uk�u{���I��↓¶aUGLRj������Ġ�
\\server\imagery\\516000_6895000.tif:34275:�t��&R��:�r�@H鑚�� �xg�▲ �.��i�(�‼�\�w‼�.�d��B��ѫ▼��BA�T`
��AuG♦�z{�§�0�X�‼��↑5�Ÿe;↨�X�-��������]�%Ԕ٤�NѸ1�'�?Z���d���!7�ʻ��X�g��kK]�Ӥ�O���♥"�$8;�����⌂Ju�����آ�8U2�3�Ǧ�?�>�
uco"Ɖ�§@���Io¶���ӭ^(�s"♫p♠y�▲�J�{m4w♂n�3�☺Td�ҩ_� �;t♣ߑ����U↔B��9c�|;▬;P`��▲x�<‼�
Desired result:
» Select-String -Pattern "Aug" $fileList
\\server\imagery\09Aug2015\506000_6717000.tif
I'm using Powershell Core v7.2 on Win10.
CodePudding user response:
If you just want to search the file names. Get-ChildItem '\server\imagery' -recurse -include aug | select-object fullname | sort fullname | more
CodePudding user response:
If you want to search the literal strings in your variable, you pass it down the pipeline like this.
$filelist | Select-String -Pattern aug -AllMatches
When you call it like you did, it's binding to the path parameter. It can either search contents of files or strings, depending on what you give it.
Select-String -Pattern aug $filelist