FOR loop to match a name from file then get 4 values from second file
<p>Hi I need some help getting this to work :)
I have a file with names in a list.
FILE A.</p>

<pre><code>SomeNameA
SomeNameB
SomeNameC
etc
</code></pre>

<p>Now I need to get a set of lines from FILE B:</p>

<pre><code>ddrObjId_1=SomeNameA
adrrObjType_1=8
adrrObjZone_1=ZONE_A
addrObjIP_1=0.0.0.0
addrObjIP2_1=0.0.0.0
addrObjId_2=SomeNameB
adrrObjType_2=8
adrrObjZone_2=ZONE_B
addrObjIP_2=0.0.0.0
addrObjIP2_2=0.0.0.0
</code></pre>

<p>starting with the line with a value which matches one of the names in FILE A, and all subsequent lines until either another match is found of the end of the file. Hope this explains it better :)</p>

<p>So when I'm finished I need a new FILE C to be generated with the data:</p>

<pre><code>address-object SomeNameA
type 1
host 0.0.0.0
mask 0.0.0.0
zone ZONE_A    
address-object SomeNameB
type 8
host 0.0.0.0
mask 0.0.0.0
zone ZONE_B
etc
</code></pre>

<p>So I have been trying some different scripts found her on StackO, and I can now scan the file for a word from my file and it gets the data, so i need it to get the values and then make a new file witch holds the commands. etc.. Here is the code not Working but it's a start. Hope someone can make sens of things for me..</p>

<pre><code>Clear-Host
$array = @('SomeNameA')


$found = @{}
Get-Content 'D:\Scripts\FileB.txt'| % {
  $line = $_
  foreach ($item in $array) {
    if ($line.Split('=')[1] -like $item) { $found[$item] = $true }
        foreach ($item in $line | Where-Object{$_ -like 'addrObjId_*=*' -or $_ -like 'addrObjType_*=*'}) {
        write-host $item
        }
  }
}

$found.Keys | Out-File "C:\results.txt"
</code></pre>