2014-06-24 72 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屬性]

回答

相關問題