2014-06-24 39 views
1

使用PowerShell对象我知道如何调用cmdlet ASYNCHRONOUSLY并绑定在数据到达时作为输出被触发的事件。如何将事件绑定到powershell命令输出流?

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 where sender is that outputCollection 
} 

如何以同步的方式做同样的事情。 [注:我应该使用Runspacepool,我可以指定给PowerShellInstance的Runspacepool属性]

回答

相关问题