如何通过powershell、batchfile剪切xml文件并基于节点将其移动到其他位置

如何通过powershell、batchfile剪切xml文件并基于节点将其移动到其他位置,xml,powershell,pst,Xml,Powershell,Pst,我需要根据节点剪切或移动XML文件, 等,我想通过搜索文件拿起如外汇 并将包含tfx的文件移动到其他位置 我试过以下方法,但没有成功 $dir = 'C:\temp\source' Get-ChildItem -Path $dir -Filter *.xml | Foreach-Object { $Instrument = Select-Xml -Xpath '/deal' -Path $_.FullName -ErrorAction SilentlyContinue If($Inst

我需要根据节点剪切或移动XML文件, 等,我想通过搜索文件拿起如外汇 并将包含tfx的文件移动到其他位置

我试过以下方法,但没有成功

$dir = 'C:\temp\source'
Get-ChildItem -Path $dir -Filter *.xml | Foreach-Object {
  $Instrument = Select-Xml -Xpath '/deal' -Path $_.FullName  -ErrorAction SilentlyContinue
  If($Instrument.node.innertext -eq "FX_Cross"){
    Move-Item "C:\temp\source\*.xml" "C:\temp\destination\FX" -Force
  } Else{
    Move-Item "C:\temp\source\*.xml" "C:\temp\destination\" -Force
  }
}

上面的任何结果都不会运行

您在那里最浪费时间(我想,我需要一个XML文件的示例来确定),我想您在这里遇到了麻烦

Move-Item "C:\temp\source\*.xml" "C:\temp\destination\FX" -Force
有了这行代码,您要移动所有XML文件,我认为您应该在循环中引用当前文件。这里就是(为了更容易调试
ForEach
循环,重写了一点点)


你应该考虑你的当前对象在你的代码>移动项命令:<代码>移动项$“C:\TEMP\Test\fx”-力< /代码>作为示例。谢谢下面的IAM提取检查M。存款1 20190204135352 N N 20190204 13:53:43 20190204135352 20190204135352 20190204 13:49∶42。
$dir = 'C:\temp\source'
$xmlFiles = Get-ChildItem -Path $dir -Filter *xml 
ForEach($xmlFile in $xmlFiles){
    $Instrument = Select-Xml -Xpath '/deal' -Path $xmlFile.FullName -ErrorAction SilentlyContinue
    If($Instrument.node.innertext -eq "FX_Cross"){
        Move-Item -Path $xmlFile.FullName -Destination "C:\temp\destination\FX" -Force
    }
    Else{
        Move-Item -Path $xmlFile.FullName -Destination "C:\temp\destination\" -Force
    }
}