我像这样编写了函数 PowerShell 模块:
Function docConvert2{
param ([string]$sourceFile, [string]$sourceFilePath)
....
....
}
我已经成功导入模块
我可以在 powershell cmdlet 中使用模块
当我在 C# 中尝试调用函数时,我得到了这样的异常
术语“docConvert2”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。
C# 代码
PowerShell pShell = PowerShell.Create();
pShell.Commands.AddCommand("import-module").AddParameter("Name", "DocConverter2");
pShell.Invoke();//works correctly
pShell.AddCommand("docConvert2");
pShell.AddParameter("sourceFile", "'addendum no-3_PREP.doc'");
pShell.AddParameter("sourceFilePath", @"'D:\New\wordler'");
pShell.Invoke();//throw exception
我的错误是什么?