首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用Powershell通过Automic scheduler解析脚本

用Powershell通过Automic scheduler解析脚本
EN

Stack Overflow用户
提问于 2019-01-03 11:03:47
回答 1查看 305关注 0票数 0

我正在做一个关于Trizetto元素的项目,据说文件名是可变的,所以我做了一个解析脚本,以确保当我们开始批量加载时,我抓取了正确的文件。在我的桌面上运行得很好,但是一旦我把它插入Automic scheduler,它就开始抱怨无法将值加载到空数组中。

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

代码语言:javascript
复制
################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\"
                }}

我希望它会将正确的文件移动到目标位置,但我得到

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2019-01-03 11:49:17

您还没有初始化文本数组:$text$i

相反,试着这样做:

代码语言:javascript
复制
$text = @()
$num = $array.Count - 1   
for ($i=0; $i -le $num; $i++ ){
    $text+= get-content $array[$i]|select -First 10

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54015795

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档