我将 xml 文件存储在当前日期文件夹中,如下所示 -请参阅此链接
现在我想读取 xml 的特定部分并将其打印在 csv 文件中。如链接How can I use the $location as input to read the xml files based on the current date folder?
我尝试使用:
$locatexml = -item -path $rptdir -itemtype Directory -Name ("XML_$(Get-Date -f yyyy_mm_dd)")
但我收到一个错误 - 一元运算符“-”后缺少表达式。 如何将当前文件夹分配给 $locatexml?这样我就可以引用当前日期文件夹中存在的所有 xml 文件?
我的代码试图读取位于日期文件夹中的 xml 文件:
从 $locatexml 中删除了 -itemtype,我将全名分配给另一个变量 $locatexml2。
$locatexml = get-item -path $reportdir -Name ("XML_$(Get-Date -f yyyy_MM_dd)")
**Do I need $locatexml2 here?**
$locatexml2 = "$($location.fullname)"
Function DoRpt($locatexml2)
{
$rptOut="Asm"
Get-ChildItem $locatexml2 | ForEach-Object {
$file = Get-Content -path $locatexml2\$_ -totalcount 15
try {
$asm = [regex]::matches($file[5], 'asm=".*" ')[0].value -replace 'asm="(.*)" ','$1'
$rptOut=$rptOut+"`n$Asm,$locatexml2\$_"
} catch {}
}
Set-Content -path $testdir\test.csv -value $rptOut
}
XML 如下所示:
<?xml version="1.0" encoding="utf-8"?>
<Rpt Version="10.0">
<Targets>
<Target="\\Shared\Data\SB\app\bin\test.dll">
<Mods>
<Mod="test.dll" asm="1.0.0000.000">
</Mod>
</Mods>
</Target>
</Targets>
</Rpt>
我尝试了所有分配 $locatexml 的方法,如下所示,但我没有通过.. 上面的代码中是否缺少我的东西?
我真的需要 $locatexml2 吗?
谢谢!