开发者

How can this way exclusion of files be achieved in PowerShell?

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 fi开发者_运维问答lter 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?


Try this:

gci *.bak -exclude *.*.bak

I tried to reply to your comment, but the code doesn't show up right. -exclude takes a string[] argument, so:

gci -recurse -filter *.bak -exclude *.*.bak,windows |? {!$_.psiscontainer}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜