如何使用铁蟒添加交换snapin

时间:2012-05-09 14:17:56

标签: python powershell ironpython exchange-server powershell-v2.0

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

def RunScript(脚本):

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

由于 Susant

1 个答案:

答案 0 :(得分:0)

在将其传递给AddScript方法之前,您可以在“脚本”中添加对Add-PSSnapin的调用。 您也可以添加:

ps = PowerShell.Create()
ps.AddCommand("Add-PSSnapin").AddParameter("Name","Microsoft.Exchange.Management.PowerShell.Admin")