简体   繁体   中英

How to add exchange snapin using iron python

Below is my Iron Python script it works fine with all the system level commands (get-process etc) but I want to add MS-Exchange snap-in to invoke exchange command. Can some one help me ?

def RunScript(script):

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

Thanks Susant

You can add a call to Add-PSSnapin in 'script' before you pass it to the AddScript method. You can also add with this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM