我正在做一个关于Trizetto元素的项目,据说文件名是可变的,所以我做了一个解析脚本,以确保当我们开始批量加载时,我抓取了正确的文件。在我的桌面上运行得很好,但是一旦我把它插入Automic scheduler,它就开始抱怨无法将值加载到空数组中。
我尝试以批处理脚本的形式加载,并通过自动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发布于 2019-01-03 11:49:17
您还没有初始化文本数组:$text$i
相反,试着这样做:
$text = @()
$num = $array.Count - 1
for ($i=0; $i -le $num; $i++ ){
$text+= get-content $array[$i]|select -First 10等
https://stackoverflow.com/questions/54015795
复制相似问题