如何在 PowerShell 中实现这种文件排除方式?
我在生产服务器上有一个 PowerShell 脚本,用于显示超过 30 天的数据库备份文件的列表。
我只需要查看扩展名为“.bak”的文件。但是,在我的脚本中没有匹配的语法或 正则表达式,所以我也开始看到扩展名为“filename.foo.bak”的文件列表。这些文件可能是服务器上的文本文件或其他配置文件,使用这些文件的程序已自动对其进行备份。
如何启用匹配过滤器以便只看到“*.bak”而不是上面提到的其他文件?
正如 mjolinor 提到的,我使用这个脚本来进行排除。
gci $paths -recurse -filter *.bak -exclude *.*.bak | ?{!$_.psiscontainer}
但是,我了解到我需要排除一些系统文件夹,例如 C:\Windows。 这又如何能够实现呢?
I have a PowerShell script on a production server to show me the list of database backup files that are older than 30 days.
I need to see only the files that have the extension of ".bak". However, in my script there is no matching syntax or regular expression, so I am also getting to see a list of files which have an extension like "filename.foo.bak". These files may be text files or other configuration files on the server for which backups have been taken automatically by the program that uses these files.
How do I enable a match filter so that I see only "*.bak" and not other files as mentioned above?
As mentioned by mjolinor, I have used this script to do the exclusion.
gci $paths -recurse -filter *.bak -exclude *.*.bak | ?{!$_.psiscontainer}
However, I have learnt that I need to exclude some system folders such as C:\Windows.
How can this be accomplished as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
我试图回复您的评论,但代码显示不正确。 -exclude 采用 string[] 参数,因此:
Try this:
I tried to reply to your comment, but the code doesn't show up right. -exclude takes a string[] argument, so: