我正在使用powershell脚本将ASCII格式的SNMP OID输出转换为char。我面临着从文本文件转换更多行的问题,它只能处理几行。如果我添加更多行,那么它只处理少数几行。我无法确定问题在我的脚本上的位置。寻找有关问题可能出现的指导。
下面给出的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 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-(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
如果我在文本文件中多次复制上述内容,则会出现问题。
此致 Naresh
答案 0 :(得分:0)
从下面的行中删除-readcount参数后,我能够解决问题。
旧行
$RawData0 = Get-Content "C:\LBOIDOUTSORT.txt" -ReadCount 1000
修改后的行
$RawData0 = Get-Content "C:\LBOIDOUTSORT.txt"
这解决了这个问题。