2017-10-11 75 views
-1

我正在使用powershell腳本將ASCII格式的SNMP OID輸出轉換爲char。我面臨着從文本文件轉換更多行的問題,它只能處理幾行文字。如果我添加更多的線,那麼它只處理很少的線。我無法確定問題在我的腳本上。尋找有關問題可能出現的指導。Powershell腳本不處理所有行,但只處理幾行

PowerShell腳本如下,腳本使用

$FileName = "C:\LBOIDOUTSORT.txt" 
if (Test-Path $FileName) { 
    Remove-Item $FileName 
} 
Get-Content "C:\LBOIDOUT.txt"| Sort-Object | get-unique >> "C:\LBOIDOUTSORT.txt" 
$RawData0 = Get-Content "C:\LBOIDOUTSORT.txt" -ReadCount 1000 
$parentarray = @() 
$parentarray += "URL Name,Server Name, IPAdress" 
foreach ($RawDataline in $RawData0) { 
    $rawinfo = $RawDataline -replace ("ltmPoolMemberTable\.ltmPoolMemberEntry\.ltmPoolMemberAddr\.|%255255| OCTET STRING- \(ascii\): | ") 
    $rawinfo = $rawinfo -split ':' 
    $rawserverip = $rawinfo[1] 
    $rawurlarray = $rawinfo[0] -split '\.' 
    $temparray = @() 
    foreach ($rawurlarrayvalue in $rawurlarray) { 
     $oid = [int]$rawurlarrayvalue 
     if (($oid -gt 44) -and ($oid -le 128)) { 
      $oid = $oid 
     } 
     else { 
      $oid = 32 
     } 
     $temparray += [char[]]$oid 
    } 
    $tempvalue = -join $temparray 
    $childarray = $tempvalue -split '/' 
    $servername = ($childarray[4] -replace " ") 
    $urlserverip = ($childarray[2] -replace" ") + "," + $servername+","+$rawserverip 
    $parentarray += $urlserverip 
} 
$parentarray 

示例文本文件的內容。

ltmPoolMemberTable.ltmPoolMemberEntry.ltmPoolMemberAddr.66.47.66.65.66.67.68.69.66.47.70.71.72.73.74.75.76.66.47.66.65.66.67.68.69.66.47.70.71.72.73.74.75.76:OCTET與字符串(ASCII) :10.0.255.9%255255 ltmPoolMemberTable.ltmPoolMemberEntry.ltmPoolMemberAddr.66.47.66.65.66.67.68.69.66.47.70.71.72.73.74.75.76.66.47.66.65.66.67.68.69.66.47.70.71.72.73.74.75.76:OCTET STRING- (ascii):10.0.255.9%255255 ltmPoolMemberTable.ltmPoolMemberEntry.ltmPoolMemberAddr.66.47.66.65.66.67.68.69.66.47.70.71.72.73.74.75.76.66.47.66.65.66.67.68.69.66.47.70.71.72.73.74.75.76: OCTET STRING-(ascii):10.0.255.9%255255 ltmPoolMemberTable.ltmPoolMemberEntry.ltmPoolMemberAddr.66.47.66.65.66.67.68.69.66.47.70.71.72.73.74.75.76.66.47.66.65.66.67.68.69.66.47.70.71.72.73.74 .75.76:OCTET STRING-(asci i):10.0.255.9%255255 ltmPoolMemberTable.ltmPoolMemberEntry.ltmPoolMemberAddr.66.47.66.65.66.67.68.69.66.47.70.71.72.73.74.75.76.66.47.66.65.66.67.68.69.66.47.70.71.72.73.74.75.76:OCTET STRING-(ascii):10.0.255.9%255255

如果我在文本文件內多次複製上述內容,則會出現問題。

問候, 納雷什

+0

谷歌1.3.6.1.4.1.3375.2.2.5.3.2.1.3給你所有的信息。 –

回答

0

我能夠從下面管道上卸下-readcount參數後,解決問題。

舊線

$RawData0 = Get-Content "C:\LBOIDOUTSORT.txt" -ReadCount 1000 

修改行

$RawData0 = Get-Content "C:\LBOIDOUTSORT.txt" 

這解決了這個問題。