Error handling Powershell:我可以拥有的输出文件类型的数量有限制吗?

Error handling Powershell:我可以拥有的输出文件类型的数量有限制吗?,error-handling,powershell-2.0,file-conversion,Error Handling,Powershell 2.0,File Conversion,我有一个Powershell(2.0)脚本,它使用Microsoft.Office.Interop.Word.WdSaveFormat递归地在Word中打开一系列html文件,然后分别使用wdFormatDocument和wdFormatDOSText参数另存为Word和文本。该脚本为每种文档类型包含一个单独的函数 昨天,需求发生了变化,现在我还需要输出一个RTF文档。我添加了$saveFormatRTF变量 $saveFormatDoc = [Enum]::Parse([Microsoft.O

我有一个Powershell(2.0)脚本,它使用
Microsoft.Office.Interop.Word.WdSaveFormat
递归地在Word中打开一系列html文件,然后分别使用
wdFormatDocument
wdFormatDOSText
参数另存为Word和文本。该脚本为每种文档类型包含一个单独的函数

昨天,需求发生了变化,现在我还需要输出一个RTF文档。我添加了
$saveFormatRTF
变量

$saveFormatDoc = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatDocument"); 
$saveFormatTxt = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatDOSText"); 
$saveFormatRTF = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatRTF");  
并得到以下错误

Unable to find type [Microsoft.Office.Interop.Word.WdSaveFormat]: make sure that the assembly containing this type is l
oaded.
At C:\users\x46332\Desktop\cgc\CGC002.PS1:68 char:76
+ $saveFormatDoc = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat] <<<< , "wdFormatDocument");
    + CategoryInfo          : InvalidOperation: (Microsoft.Offic...rd.WdSaveFormat:String) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

Unable to find type [Microsoft.Office.Interop.Word.WdSaveFormat]: make sure that the assembly containing this type is l
oaded.
At C:\users\x46332\Desktop\cgc\CGC002.PS1:69 char:76
+ $saveFormatTxt = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat] <<<< , "wdFormatDOSText");
    + CategoryInfo          : InvalidOperation: (Microsoft.Offic...rd.WdSaveFormat:String) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

Unable to find type [Microsoft.Office.Interop.Word.WdSaveFormat]: make sure that the assembly containing this type is l
oaded.
At C:\users\x46332\Desktop\cgc\CGC002.PS1:70 char:76
+ $saveFormatRTF = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat] <<<< , "wdFormatRTF");
    + CategoryInfo          : InvalidOperation: (Microsoft.Offic...rd.WdSaveFormat:String) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound
找不到类型[Microsoft.Office.Interop.Word.WdSaveFormat]:请确保包含此类型的程序集为l
满载而归。
在C:\users\x46332\Desktop\cgc\CGC002.PS1:68 char:76

+$saveFormatDoc=[Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat]我做了一些进一步的测试,几天后我能够像预期的那样顺利地转换。我还测试了用一个脚本转换到每种格式……除了一些特殊字符的时髦输出格式外,一切都很好


因此,我猜没有限制,我的测试似乎证明了这一理论。

如果我启动了新的Powershell 2会话,请执行
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.Interop.Word”)
,然后复制粘贴你的3行代码,它可以工作。所有代码都可以单独工作。对不起,无法以任何方式复制。对我来说,它使用
C:\Windows\assembly\GAC\u MSIL\Microsoft.Office.Interop.Word\14.0.0.0\uu71e9bce111e9429c\Microsoft.Office.Interop.Word.dll