1

下面是我的 Iron Python 脚本,它适用于所有系统级命令(get-process 等),但我想添加 MS-Exchange 管理单元来调用交换命令。有人能帮我吗 ?

定义运行脚本(脚本):

runspace = RunspaceFactory.CreateRunspace()
runspace.Open()
pipeline = runspace.CreatePipeline()
cache = System.IO.Path.GetTempFileName()
pipeline.Commands.AddScript(script)

pipeline.Commands.Add("Out-String")
results = pipeline.Invoke()
pickled = []
for thing in results:
    pickled.append(thing.ToString())
return pickled

谢谢苏珊特

4

1 回答 1

0

Add-PSSnapin在将调用传递给 AddScript 方法之前,您可以在“脚本”中添加调用。您还可以添加以下内容:

ps = PowerShell.Create()
ps.AddCommand("Add-PSSnapin").AddParameter("Name","Microsoft.Exchange.Management.PowerShell.Admin")
于 2012-05-09T14:32:54.483 回答