Q:

Finding  tags in HTML files in Powershell

I want to create a simple code in Powershell that just checks what images are not used in a folder of HTMl files.  So I want to open each HTML file locally (not via URI) and retrieve all the  tags.  Doesn't sound too horrible. 
I've done my research and it was going well, I came up with this code:
Foreach ($imageFile in $imageFiles){
    Foreach ($file in $HTMLFiles)
    {
        Write-Debug "Processing: $file"                    
        $html = New-Object -ComObject "HTMLFile"
        $source = Get-Content -Path $file. FullName -Raw
        $html. IHTMLDocument2_write($source);       
        $nbImages = $html.Images.length        

        ForEach ($i in $html. Images){
            #$i.getTags("src")
        }          
    } 
}

Question 1: I'm working with HTML files that I (re)convert to HTML files to get access to useful methods.  Is there a simple way? 
Question 2 and problem: I just can't find a way to go through my collection of image tags.  How do I do that? 
I've checked how images my code finds in the sources, and it's correct.  I just want to get the info from the collection itself. 
Thank you for your help, I'm really stuck here! 

A:

PowerShell makes you think it's got equivalents for loops but doesn't. 
A foreach does not do the same thing as |%{...}. 
In my example, I have to replace my second foreach by how I retrieve my $HTMLFiles and redirect it to a %{}.  That way, PS "knows" what's in the $htmlFiles variable.  
Conclusion: 
Prefer pipes than foreach loops.  Pipes lets PS keep track of what the result of an expression thanks to pipes.  Foreach loops seem to prevent it from doing that. 
Conclusion 2 and more precision:
Finally, i've found a way to do it with a foreach. 
Instead of:
ForEach ($i in $html. Images){
  ...
}  

Do:
$images= @($html. Images)
$images | ForEach {...}

