Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

Показать сообщение отдельно

Старожил


Сообщения: 211
Благодарности: 2

Профиль | Отправить PM | Цитировать


Цитата YuS_2:
попробуйте так проверить: »
Скрытый текст
Код: Выделить весь код
param (
	#[parameter(Mandatory=$true)]
	[string]$outfile = 'D:\PowerShell\готовые\all_phone.csv',
	$enc1 = 65001,
	$enc2 = 28591,
	[int[]]$SelectTable = 1
)

#---Эту секцию можно удалить после однократного запуска скрипта от имени админа ------------------
# Установка дополнительного модуля PowerHTML, для независимого парсинга HTML
# Может потребоваться ручное подтверждение установки. 
if (!(get-module -list powerhtml)) {
	write-verbose "Installing PowerHTML module for the current user..."
	install-module powerhtml #-scope currentuser
}
#-----------------------------------------------------------------------------------------

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  = gc 'D:\PowerShell\готовые\all_ip.txt'
$ips = 130..190 |%{$n=$_;$arr|%{"$_"+$n}}|sort

$ips|% -parallel {
	if (test-connection $_ -count 1 -q -timeout 1){
		try {
			$a = (iwr $_).content
			$content = if ($a -match [char]208){
				if ($a -match 'windows-1251'){
					$enc1,$enc2 = 1251,1252
					$a|convert $enc1 $enc2
				} else {$a|convert $using:enc1 $using:enc2}
			} else {$a}
			$html = [net.webutility]::htmldecode($content)|convertfrom-html
			[array]$tables = $html.selectnodes('//table')
			# Исключение вложенных таблиц:
			$tables = $tables|?{$_.selectnodes('.//table') -eq $null}
			$tbl = $tables[$using:number]|%{$n=0}{
				$tr = $_.selectnodes('.//tr')
				$headers = @()
				if ($headers = $_.selectnodes('.//th')){
					$headers = ($headers|select -exp innertext).trim()
				} else {
					$headers = 1..([linq.parallelenumerable]::max(
						[linq.parallelenumerable]::asparallel(
							($tr|%{$_.selectnodes('.//td').count})
						)
					))|%{"H$_"}
				}
				$rowind = ,1 * $headers.count
				$tr|?{$_.selectnodes('.//td') -ne $null}|%{
					$row = $_.selectnodes('.//td')|%{
						$attr = $_.attributes
						if ($attr){
							$rowspan = ($attr|? name -eq 'rowspan').value
							$colspan = ($attr|? name -eq 'colspan').value
						}
						[pscustomobject]@{
							'InnerText' = $_.innertext
							'RowSpan' = if($rowspan){[int]$rowspan} else {1}
							'ColSpan' = if($colspan){[int]$colspan} else {1}
						}
					}
					$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
				}
			}
			$parr1 = $tbl.h1
			if ($tbl.h2 -ne $null) {$parr2 = $tbl.h2} else {$parr2 = $tbl.h3}
			[pscustomobject]@{
				'IP'				= $_
				'MAC-адрес' 		= if ([array]::indexof($parr1,'MAC-адрес') -ne -1) {
										$parr2[([array]::indexof($parr1,'MAC-адрес'))]
									  } else {$parr2[([array]::indexof($parr1,'MAC Address'))]}
				'Номер телефона'	= if ([array]::indexof($parr1,'Номер телефона') -ne -1) {
										$parr2[([array]::indexof($parr1,'Номер телефона'))]
									  } elseif ([array]::indexof($parr1,'Номер телефона 1') -ne -1) {
									  	$parr2[([array]::indexof($parr1,'Номер телефона 1'))]
									  } else {
									  	$parr2[([array]::indexof($parr1,'Phone DN'))]
									  }
				'Серийный номер'	= if ([array]::indexof($parr1,'Серийный номер') -ne -1) {
										$parr2[([array]::indexof($parr1,'Серийный номер'))]
									  } else {$parr2[([array]::indexof($parr1,'Serial Number'))]}
				'Номер модели'		= if ([array]::indexof($parr1,'Номер модели') -ne -1) {
										$parr2[([array]::indexof($parr1,'Номер модели'))]
									  } else {$parr2[([array]::indexof($parr1,'Model Number'))]}
			}
		} catch {
			write-host Ошибка: $_ -for red
		}
	}
} -throttlelimit 4 |export-csv $outfile -notype -enc utf8 -d ';' -append
Скрытый текст
Код: Выделить весь код
PS C:\Windows\System32> D:\PowerShell\готовые\phone_p7.ps1
SetValueInvocationException: D:\PowerShell\готовые\phone_p7.ps1:28
Line |
  28 |  [net.servicepointmanager]::securityprotocol = 'ssl3,tls,tls11,tls12'
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception setting "securityprotocol": "The requested security protocol is not supported."

ForEach-Object: D:\PowerShell\готовые\phone_p7.ps1:32
Line |
  32 |  $ips|% -parallel {
     |       ~~~~~~~~~~~~~
     | The value of the using variable '$using:number' cannot be retrieved because it has not been set in the local
     | session.

PS C:\Windows\System32>


похоже надо доустановить, щас решу отпишусь.

Отправлено: 14:00, 09-05-2020 | #113