Powershell 文件获取
我正在寻找一些帮助来创建 PowerShell 脚本。
我有一个文件夹,其中有很多文件,我只需要其中包含以下两个内容的文件:
必须具有与文件 file1 中相同的任何匹配字符串模式(文件 1 的内容是
- IND 23042528525
或INDE 573626236
或DSE3523623
它可以是更多这样的字符串)文件中的日期也位于
03152022
和03312022
,格式为mmddyyyy
。 文件可能很旧,因此与创建时间无关。
然后将结果保存在 csv 中,其中包含满足上述条件的文件的路径。
目前我使用以下命令,该命令仅提供满足 1 条件的文件。
$table = Get-Content C:\Users\username\Downloads\ISIN.txt
Get-ChildItem `
-Path E:\data\PROD\server\InOut\Backup\*.txt `
-Recurse |
Select-String -Pattern ($table)|
Export-Csv C:\Users\username\Downloads\File_Name.csv -NoTypeInformation
Am looking for some help to create a PowerShell script.
I have a folder where I have lots of files, I need only those file that has below two content inside it:
must have any matching string pattern as same as in file file1 (the content of file 1 is
-IND 23042528525
orINDE 573626236
orDSE3523623
it can be more strings like this)also have date inside the file in between
03152022
and03312022
in the formatmmddyyyy
.
file could be old so nothing to do with creation time.
then save the result in csv containing the path of the file which fulfill above to conditions.
Currently am using the below command that only gives me the file which fulfilling the 1 condition.
$table = Get-Content C:\Users\username\Downloads\ISIN.txt
Get-ChildItem `
-Path E:\data\PROD\server\InOut\Backup\*.txt `
-Recurse |
Select-String -Pattern ($table)|
Export-Csv C:\Users\username\Downloads\File_Name.csv -NoTypeInformation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要测试文件是否包含一系列关键字中的某个关键字,您可以使用正则表达式。如果您还想在该文件中查找至少一个格式为“MMddyyyy”的有效日期,则需要做一些额外的工作。
尝试以下:
To test if a file contains a certain keyword from a range of keywords, you can use regex for that. If you also want to find at least one valid date in format 'MMddyyyy' in that file, you need to do some extra work.
Try below: