简体   繁体   English

处理.svd文件时,索引超出了数组错误的范围

[英]Index was outside the bounds of the array error when processing .svd file

clear

# Powershell scripts used to mask Private Personal Information on data files.

# path to PERM file
$path = "MYURL\ABS.SVD"

# get file content
$content = Get-Content $path

$content | ForEach-Object {
    $mask50 = 'X' * 50   # variables to makes fields by letter according to length
    $mask30 = 'Y' * 30
    $mask20 = 'A' * 20
    $mask08 = 'Z' * 8
    $mask05 = 'B' * 5
    $mask16 = 'C' * 16

    # if statement, if the string is at position 0-10, and begins with
    # 'STARTDELIV' then run replace statement
    if ($_.Substring(0,10) -eq 'STARTDELIV') {
        $SplitString = $_.Split('|')

        $SplitString[3] = $mask30    # Fields : To Fax Name
        $SplitString[4] = $mask20    # Fields : To fax Number
        $SplitString[9] = $mask50    # Fields : To EMail Address

        $SplitString -join '|'
    } else {
        $_
    }
} | Out-File "MYURL\ABS-Output.svd" -Encoding ASCII

I have a script which masked certain fields in a data file (fields seperated by '|'). 我有一个脚本,可屏蔽数据文件中的某些字段(用“ |”分隔的字段)。 I have done a lot of these and they work fine. 我已经做了很多这些工作,并且效果很好。 However, when I copy this exact file to another folder to use a different data file (.svd) I get the "Index was outside the bounds of the array", I've seen a few other threads on this but none really answer my query. 但是,当我将此精确文件复制到另一个文件夹以使用其他数据文件(.svd)时,出现“索引超出数组范围”的信息,我看到了其他一些线程,但没有一个能真正回答我的问题查询。

Curious as to why it still works in a particular folder location but not the other (I am changing the input and output urls to direct to the new folder). 好奇为什么它仍然可以在特定的文件夹位置而不是其他位置工作(我正在更改输入和输出URL以直接到新文件夹)。

Error below: 错误如下:

Index was outside the bounds of the array.
AtMYURL-Masked-Fields.ps1:28 char:3
+         $SplitString[3] = $mask30                                                    #To Fax Name
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], IndexOutOfRangeException
    + FullyQualifiedErrorId : System.IndexOutOfRangeException

Answer provided by @lit @lit提供的答案

"There is at least one record starting with STARTDELIV that does not have enough fields. find /I "STARTDELIV" "MYURL\\ABS.SVD" " “至少有一个以STARTDELIV开头的记录没有足够的字段。找到/ I“ STARTDELIV”“ MYURL \\ ABS.SVD”“

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 索引超出了阵列powershell的范围 - Index was outside the bounds of the array powershell 为什么Get-Date引发Index超出数组错误的范围? - Why Get-Date throws Index was outside the bounds of the array error? 我的脚本给出错误“索引在数组的边界之外” Powershell - My script is giving the error “Index was outside bounds of array” Powershell Powershell - New-Object:索引超出了数组的范围 - Powershell - New-Object : Index was outside the bounds of the array 新项IIS:\\ Sites \\ SiteName - 索引超出了数组的范围 - New-Item IIS:\Sites\SiteName - Index was outside the bounds of the array 发布模块失败并出现 NuGet.Build.Tasks.Pack.targets(198,5) 错误:索引超出了数组的范围 - Publish-Module fails with NuGet.Build.Tasks.Pack.targets(198,5) error : Index was outside the bounds of the array “PS c:\> New-WebSite -Blah:”抛出索引超出了数组的范围 - “PS c:\> New-WebSite -Blah:” throws Index was outside the bounds of the array 数组索引超出范围。 丢弃的接口数据包:字符串(PowerShell) - Array index out of bounds. Interface Packets dropped: String (PowerShell) 当值不为空时,无法索引到空数组错误 - Cannot index into a null array error when value is not null 隔离数组中的相似文件名以进行额外处理 - Isolate similar file names in an array for additional processing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM