1

Im trying to iterate through multiple HTML files in multiple computers.

My code is below:

ForEach ($system in (Get-Content C:\temp\computers.txt)) {

    $folder = "\\$system\c`$\ProgramData\Autodesk\AdLM\"
    Get-ChildItem $folder *.html  |
    Foreach-Object {
        $c = $_.BaseName
        $html = New-Object -ComObject "HTMLFile"
        $HTML.IHTMLDocument2_write($(Get-content $_.Name -Raw ))
        $para1 = $HTML.getElementById('para1') | % InnerText
        Add-Content -path c:\temp\results.csv "$c,$system,$para1"
    }
 }

I'm getting the following error:

New-Object : Cannot find parameter Raw
6
  • @BryceMcDonald - The New-Object cmdlet is a built-in PowerShell cmdlet. The querent should look at gallery.technet.microsoft.com/Powershell-Tip-Parsing-49eb8810 for handling HTML files using the Document Object Model. Commented Nov 27, 2017 at 15:12
  • @JeffZeitlin I'm aware of the cmdlet, for some reason I couldn't see where he had it in his code but I do now. I'll keep drinking this coffee and hope it helps. Commented Nov 27, 2017 at 15:14
  • Also relevant: stackoverflow.com/questions/24977233/parse-local-html-file Commented Nov 27, 2017 at 15:18
  • @Ankh2054 What is "localfiée"? Commented Nov 27, 2017 at 15:27
  • let me check again as I've realised I'm using powershell2 which does not have Raw parameter. Commented Nov 27, 2017 at 15:29

1 Answer 1

2

You can use the Internet Explorer COM object to do what you'd like the HTMLFile COM object to do. HTMLFile isn't working 100% in all versions of Powershell, so this is a viable alternative.

ForEach ($system in (Get-Content C:\temp\computers.txt)) {
  $folder = "\\$system\c`$\ProgramData\Autodesk\AdLM\"
  Get-ChildItem $folder *.html  |
  ForEach-Object {
    $c = $_.BaseName
    $ie=New-Object -ComObject InternetExplorer.Application
    $ie.Navigate("$_")
    while ($ie.busy -eq $true) {
      Start-Sleep -Milliseconds 500
    }
    $doc=$ie.Document
    $elements=$doc.GetElementByID('para1')
    $elements.innerText | ForEach-Object { Add-Content -path c:\temp\results.csv "$c,$system,$para1" }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.