Reputation: 1153
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
Upvotes: 1
Views: 2906
Reputation: 1870
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" }
}
}
Upvotes: 2