如何从XML文件中读取值并将值作为逗号分隔的字符串传递给powershell中的exclude参数? [英] How to read values from XML file and pass the values as a comma seperated string to exclude parameter in powershell ?

查看:121
本文介绍了如何从XML文件中读取值并将值作为逗号分隔的字符串传递给powershell中的exclude参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有xml文件,其中包含少量文件的名称。我想读取这些文件名并将其作为逗号分隔的字符串传递给电源外壳中的Exclude命令。



我尝试了什么:



我有xml文件,其中包含几个文件的名称。

我使用下面的命令从\\Test \\中删除文件\\ abc位置。但是,在删除文件时,我不想删除文件名中包含abc或xyz的文件。



将来我可能会需要排除文件名中包含pqr(例如)的文件。因此,我需要在xml文件中包含所有这些单词,而不是在下面的命令中对其进行硬编码。我将读取该xml文件,并将这些名称作为逗号分隔字符串作为参数传递给下面命令中的排除。



Get-ChildItem -Path\\\ \\Test \abc-Exclude * abc *,* xyz * -Recurse | Where-Object {$ _.LastWriteTime -lt(Get-Date).AddDays(-4)} |删除项目



请让我知道如何读取xml文件并将值作为逗号分隔字符串传递给Exclude命令?

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 ?

推荐答案

_。LastWriteTime -lt(Get-Date).AddDays(-4)} |删除项目



请让我知道如何读取xml文件并将值作为逗号分隔字符串传递给Exclude命令?
_.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 ?


这篇关于如何从XML文件中读取值并将值作为逗号分隔的字符串传递给powershell中的exclude参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆