我试图在多台计算机中迭代多个HTML文件。
我的代码如下:
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"
}
}
我得到了以下错误:
New-Object : Cannot find parameter Raw
发布于 2017-11-27 15:29:50
您可以使用对象来执行您希望HTMLFile COM对象做的事情。HTMLFile并不是在所有版本的Powershell中都能100%工作,所以这是一个可行的选择。
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" }
}
}
https://stackoverflow.com/questions/47514065
复制相似问题