Jenkins PowerShell插件-返回Null

Jenkins PowerShell插件-返回Null,powershell,jenkins,ms-word,Powershell,Jenkins,Ms Word,我正在尝试通过Jenkins插件运行PowerShell脚本,该脚本将Word文档转换为文本,但会出现空类型错误。从机是一个Win 2008 box,Jenkins在其上作为服务运行,该服务作为管理员运行。我试过: 通过在本地运行这些命令,验证这些命令是否在远程设备上工作 使用Windows批处理运行PowerShell脚本(相同错误) 通过Jenkins插件运行命令 脚本($Doc被设置为空): 确认a)有一个文件,b)我得到一个Word对象。同样,所有这些都可以在遥控箱上正常工作 $Wo

我正在尝试通过Jenkins插件运行PowerShell脚本,该脚本将Word文档转换为文本,但会出现空类型错误。从机是一个Win 2008 box,Jenkins在其上作为服务运行,该服务作为管理员运行。我试过:

  • 通过在本地运行这些命令,验证这些命令是否在远程设备上工作
  • 使用Windows批处理运行PowerShell脚本(相同错误)
  • 通过Jenkins插件运行命令
脚本(
$Doc
被设置为空):

确认a)有一个文件,b)我得到一个Word对象。同样,所有这些都可以在遥控箱上正常工作

$Word

Application : Microsoft.Office.Interop.Word.ApplicationClass Creator : 1297307460 Parent : Microsoft.Office.Interop.Word.ApplicationClass Name : Microsoft Word Documents : System.__ComObject Windows : System.__ComObject ActiveDocument : . . . 更新:

根据Andreas M的建议更改了脚本:

Foreach ($File in $Files) {
    # open document in Word
    echo File: $File.fullname
    $Error.Clear() # Clear all other errors
    $Doc = $Word.Documents.Open($File.FullName)
    echo "Error count:" $Error.Count # Dump number of errors
    $Error # Dump errors    
        echo "Doc:" $Doc
同样的错误,但奇怪的是,Word.Doc.Open调用没有报告错误

File:
C:\jenkins\workspace\eggplant-Test\DVA.docx
Error count:
0
Doc:
You cannot call a method on a null-valued expression.
At C:\Users\PENDAN~1.MDZ\AppData\Local\Temp\hudson3349169014447704754.ps1:23 ch
ar:12
+     $Doc.close <<<< ()
    + CategoryInfo          : InvalidOperation: (close:String) [], RuntimeExce 
   ption
    + FullyQualifiedErrorId : InvokeMethodOnNull
文件:
C:\jenkins\workspace\eggplant Test\DVA.docx
错误计数:
0
文件:
不能对空值表达式调用方法。
在C:\Users\PENDAN~1.MDZ\AppData\Local\Temp\hudson33491690147704754.ps1:23 ch
ar:12

+$Doc.close尝试以下操作。首先,检查管理员是否有权打开给定位置下的文件。使用错误扩展脚本输出检查为什么
$Word.Documents.Open($File.FullName)
返回
$null

$Error.Clear() # Clear all other errors
$Doc = $Word.Documents.Open($File.FullName)
$Error.Count # Dump number of errors
$Error # Dump errors
也许您可以检索有关
Open
失败原因的其他信息


更新:您可能需要更改Com/Dcom设置->检查此问题的答案。

更新了初始问题并输出错误。我已经使用Jenkins使用的相同用户名/密码登录到远程框,并且能够毫无问题地运行脚本。非常感谢您提供的链接。我有99%的信心,我自己永远不会朝那个方向看。虽然这不是DCOM的问题,但它是将桌面添加到SysWow目录(在该链接中提到)中修复了它。再次感谢你。
File:
C:\jenkins\workspace\eggplant-Test\DVA.docx
Error count:
0
Doc:
You cannot call a method on a null-valued expression.
At C:\Users\PENDAN~1.MDZ\AppData\Local\Temp\hudson3349169014447704754.ps1:23 ch
ar:12
+     $Doc.close <<<< ()
    + CategoryInfo          : InvalidOperation: (close:String) [], RuntimeExce 
   ption
    + FullyQualifiedErrorId : InvokeMethodOnNull
$Error.Clear() # Clear all other errors
$Doc = $Word.Documents.Open($File.FullName)
$Error.Count # Dump number of errors
$Error # Dump errors