Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have xml file which contains names of few files. I want to read those file names and pass it as a comma seperated string to Exclude command in power shell.

What I have tried:

I have xml file which contains names of few files.
I am using below command to delete files from \\Test\abc location. However, while deleting files, I don't want to delete those files which contains "abc" or "xyz" in their file name.

In future, I may need to exclude the files which has "pqr" (say) in their file name. So instead of hard coding it in below command, I need to include all those words in xml file. I will read that xml file and pass those names as comma seperated string as a parameter to "Exclude" in below command.

Get-ChildItem –Path "\\Test\abc" -Exclude *abc*,*xyz* -Recurse | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-4)} | Remove-Item

Please let me know how I can read the xml file and pass the values as a comma seperated string to Exclude command ?
Posted
Updated 7-Aug-19 20:29pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900