我有存储在当前日期文件夹中的xml文件,如下所示 - Refer this link
现在我想读取xml的特定部分并在csv文件中打印该文件。 如链接中一样如何使用$ location作为输入来仅基于当前日期文件夹读取xml文件?
如何读取存储在当前日期文件夹中的xml文件?
我试着使用:
$locatexml = -item -path $rptdir -itemtype Directory -Name ("XML_$(Get-Date -f yyyy_mm_dd)")
但我得到一个错误 - 缺少一元运算符后表达 ' - '。 如何将当前文件夹分配给$ locatexml?,以便我能够引用当前日期文件夹中存在的所有xml文件?
我的代码试图读取位于日期文件夹中的XML文件:
从$ locatexml删除-itemtype,我分配FULLNAME另一个变量$ 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>
我试图分配如下metnioned的$ locatexml的所有方法,但我没有得到过。是有什么我缺少的上面的代码?
我真的需要$ locatexml2吗?
谢谢!
'-item'?也许是'get-item'? –
如果我使用Get-Item我得到的错误:get-Item:找不到与参数名称item-type匹配的参数。此外,当它试图索引存储在当前日期文件夹中的xml文件时,我得到文件夹访问被拒绝错误。我是否需要在此设置一些权限? –
你不需要带'Get-Item'或'Get-ChildItem'的'-ItemType'开关。它正在与'New-Item'一起使用来指定你要创建什么样的项目。 – vonPryz