处理.svd文件

时间:2018-04-11 13:10:16

标签: powershell

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

我有一个脚本屏蔽了数据文件中的某些字段(由' |'分隔的字段)。我做了很多这些并且它们工作正常。但是,当我将这个确切的文件复制到另一个文件夹以使用不同的数据文件(.svd)时,我得到了#34;索引超出了数组的范围",我已经看到了一些其他的线程在此,但没有人真正回答我的问题。

很好奇为什么它仍然在特定的文件夹位置而不是另一个(我正在更改输入和输出URL以指向新文件夹)。

以下错误:

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

1 个答案:

答案 0 :(得分:0)

@lit提供的答案

"至少有一条以STARTDELIV开头的记录没有足够的字段。找/我" STARTDELIV" " MYURL \ ABS.SVD" "