I have xml files stored in the current date folder as in here – Refer this link
Now I want to read a specific part of the xml and print that in a csv file.
As in the link How can I use the $location as input to read the xml files based on the current date folder only?
I tried using:
$locatexml = -item -path $rptdir -itemtype Directory -Name ("XML_$(Get-Date -f yyyy_mm_dd)")
But I get an error – Missing expression after unary operator ‘-‘.
how can I assign the current folder to $locatexml? so that I can be able to refer to all the xml files that exist for the current date folder?
My code which is trying to read the xml files located in the date folder:
Removed -itemtype from the $locatexml, I am assigning the fullname to another variable $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
}
The XML looks like below:
<?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>
I tried all the methods of assigning the $locatexml as metnioned below, but I am not getting through.. Is there something I am missing in the above code?
DO I really need $locatexml2 here?
Thanks!
Do a
dirin the parent directory, indicating the folder name you are looking for. I am assuming$rptdiris a string indicating the parent directory where the date-named subdirectories reside.