【问题标题】:Parsing script with Powershell through Automic scheduler通过自动调度程序使用 Powershell 解析脚本
【发布时间】:2019-01-03 03:03:47
【问题描述】:

我在 Trizetto Elements 上做一个项目,据说文件命名是可变的,所以我制作了一个解析脚本,以确保在开始批量加载时获取正确的文件。在我的桌面上运行良好,但一旦我将其插入 Automic 调度程序,它就会开始抱怨无法将值加载到空数组中。

我尝试作为批处理脚本加载并通过自动 Powershell 解释器运行并得到类似的结果

################Load file content into variables##########
$array = GCI -Path "F:\Originpath"
$num = $array.Count - 1   
for ($i=0; $i -le $num; $i++ ){$text[$i]

    $text[$i]= get-content $array[$i]|select -First 10

    "Parsing first ten rows of file" + " " + ($array[$i])

     write-host $text[$i]}
####################Evaluate file contents for match####################
      for ($b=0; $b -le $num; $b++ ){
      if($text[$b]| Select-String -Pattern '.*,H9047,.*,51,'){
           Move-Item -path $array[$b] -destination "F\:destination path\"
                }}

我希望它将正确的文件移动到目的地,而不是我得到

c:\>powershell -File F:\Automic\Agents\Windows\Resources\0001\0002378703\0002378703_0001.ps1 
Cannot index into a null array.
At F:\Automic\Agents\Windows\Resources\0001\0002378703\0002378703_0001.ps1:5 char:5
+     $text[$i]= get-content ($array[$i])|select -First 10
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

【问题讨论】:

  • 做到了!感谢您的帮助。

标签: powershell text-parsing automic


【解决方案1】:

你还没有初始化文本数组:$text[$i]

尝试类似的方法:

$text = @()
$num = $array.Count - 1   
for ($i=0; $i -le $num; $i++ ){
    $text+= get-content $array[$i]|select -First 10

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-06
    • 1970-01-01
    • 2017-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多