I am trying to get data from a folder that contains several other xml files. My script is supposed to take a string from a csv, look through these folders and return the xml that contains my string from the csv.
Right now my code gives me a whole bunch of blank lines.
My CSV looks like
Key,STIGS
V-2258, APACHE SITE 2
V-2258, Windows 7
My code returns “APACHE SITE 2” for $firststig
So if I have file1.xml, file2.xml, file3.xml.
file2 has a node with the word “APACHE SITE 2” it will select that file and I can pull data from it.
This is my code:
$key = “Insert Key” # the user is prompted for 2258#
$csv = Import-CSV “file.csv”
$firststig = (($csv | where {$_.KEY -eq $key }).STIGS) | select -first 1
$dir = “Path”
$xmlfiles = Get-ChildItem $dir -Filter *.xml | Foreach{
$file = $_.Name
[xml]$xmldata = Get-content “Path$file”
$xmldata = $xmldata | Where-Object {$xmldata.Benchmark.title -contains $firststig}
write-host $xmldata.Benchmark.title
}
im not sure how to insert my sample from my xml file into this thread.
I believe $xmldata = $xmldata | Where-Object {$xmldata.Benchmark.title -contains $firststig} is the issue.