c# - How to bind event to powershell command output stream? -
c# - How to bind event to powershell command output stream? -
using powershell object know how invoke cmdlets asynchronously , bind event gets fired , when info arrives output.
powershell powershellinstance = powershell.create(); //add necessary commands psdatacollection<psobject> outputcollection = new psdatacollection<psobject>(); outputcollection.dataadded += outputcollection_dataadded; iasyncresult result = powershellinstance.begininvoke<psobject, psobject>(null, outputcollection); void outputcollection_dataadded(object sender, dataaddedeventargs e) { //process output sender outputcollection } how same in synchronous manner. [note: should utilize runspacepool, can specify powershellinstance's runspacepool property]
to accomplish objective, should utilize variant of invoke method. http://msdn.microsoft.com/en-us/library/hh459547%28v=vs.85%29.aspx
c# powershell
Comments
Post a Comment