Код:

param (
#[parameter(Mandatory=$true)]
$encode = 65001,
[string]$outfile = 'table.csv',
[int]$number = 1
)
function convert ($from, $to){
begin{
$fenc = [text.encoding]::getencoding($from)
$tenc = [text.encoding]::getencoding($to)
}
process{
$a = $tenc.getbytes($_)
$fenc.getstring($a)
}
}
[net.servicepointmanager]::securityprotocol = 'ssl3,tls,tls11,tls12'
[array]$arr = $((Get-Netipaddress |? ipaddress -match "^10\.").ipaddress -replace "\d+$")
$ips = 130..190 |%{$n=$_;$arr|%{"$_"+$n}}|sort|?{test-connection $_ -count 1 -q}
$ips|%{
$html = new-object -com "HTMLFile"
$html.ihtmldocument2_write(($h = irm $_))
if ($h -match [char]208){
$html = new-object -com "HTMLFile"
$html.ihtmldocument2_write($(irm $_|convert $encode 28591))
}
$tables = $html.getelementsbytagname("table")
$tbl = ($tables|?{($_.getelementsbytagname('table')|%{$_}).count -eq 0})[$number]|%{
$headers = @();
$tr = $_|%{$_.getelementsbytagname("tr")}
if($headers = $tr|?{$_.firstchild().tagname -eq 'th'}|
%{$_.getelementsbytagname("th")}|select -exp innertext){
$headers = $headers.trim()
} else {
$headers = 1..([linq.parallelenumerable]::max(
[linq.parallelenumerable]::asparallel($tr.lastchild().cellindex)
)+1)|%{"H$_"}
}
$rowind = ,1 * $headers.count
$tr.where({$_.firstchild().tagname -eq 'td'})|%{
$row = $_.getelementsbytagname("td") |? innertext -ne $null| select innertext,rowspan,colspan
try {
$str = [ordered]@{}
$k=0
foreach ($item in $row){
if ($rowind[$k] -gt 1){
while ($rowind[$k] -gt 1){
$str[$headers[$k]] = $null
$rowind[$k] -= 1
$k++
}
}
if (($colspan = $item.colspan) -gt 1) {
$str[$headers[$k]] = if($item.innertext){
$item.innertext.trim()
} else {$null}
if ($item.rowspan -gt 1){$rowind[$k] = $item.rowspan}
$k++
while ($colspan -gt 1){
$str[$headers[$k]] = $null
$colspan -=1
if ($rowind[$k] -gt 1){$rowind[$k]-=1}
$k++
}
} else {
$str[$headers[$k]] = if($item.innertext){
$item.innertext.trim()
} else {$null}
if ($item.rowspan -gt 1){$rowind[$k] = $item.rowspan}
$k++
}
}
[pscustomobject]$str
} catch {
write-host Разметка заголовков не соответствует размерам строк -for red
write-host $_ -for cyan
}
}
}
[pscustomobject]@{
'IP' = $_
'MAC-адрес' = $tbl[([array]::indexof($tbl.h1,'MAC-адрес'))].h2
'Номер телефона' = if ([array]::indexof($tbl.h1,'Номер телефона') -ne -1){
$tbl[([array]::indexof($tbl.h1,'Номер телефона'))].h2
} else {
$tbl[([array]::indexof($tbl.h1,'Номер телефона 1'))].h2
}
'Серийный номер' = $tbl[([array]::indexof($tbl.h1,'Серийный номер'))].h2
'Номер модели' = $tbl[([array]::indexof($tbl.h1,'Номер модели'))].h2
}
} |export-csv $outfile -notype -enc utf8 -d ';'