メールをあるアカウントから別のアカウントに移動する Exchange Powershell スクリプトがあります。Powershell を介してコードを呼び出すと、リアルタイムのデータ統計が提供されます。それをキャプチャして、その「ライブフィード」を提供するテキストボックスにフィードするにはどうすればよいですか。ご協力いただきありがとうございます。
public void RunPowerShell()
{
Cursor.Current = Cursors.WaitCursor;
RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();
PSSnapInException snapInException = null;
Runspace runSpace;
//create the runspace
runSpace = RunspaceFactory.CreateRunspace(rsConfig);
//insert try here
runSpace.Open();
//for exchange 2010 use "Microsoft.Exchange.Management.PowerShell.E2010"
rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out snapInException);
//set up the pipeline to run the powershell command
Pipeline pipeLine = runSpace.CreatePipeline();
//create the scripts to use
String sScript = "Add-MailboxPermission -Identity " + FromEmailAccount.Text + " -User Administrator -AccessRights FullAccess";
String sScript1 = "Add-MailboxPermission -Identity " + ToEmailAccount.Text + " -User Administrator -AccessRights FullAccess";
String sScript2 = "Export-Mailbox -Identity " + FromEmailAccount.Text + " -TargetMailbox " + ToEmailAccount.Text + " -TargetFolder " + FromEmailAccount.Text + " -Confirm:$false";
//invoke the scripts
pipeLine.Commands.AddScript(sScript);
pipeLine.Commands.AddScript(sScript1);
pipeLine.Commands.AddScript(sScript2);
Collection<PSObject> commandResults = pipeLine.Invoke();
//loop through the results of the command and load the ?
foreach (PSObject results in commandResults)
{
richTextBox1.Text = results.ToString();
//MessageBox.Show(results.Properties["DisplayName"].Value.ToString(),@"Name");
}
//close the pipelin and runspace
pipeLine.Dispose();
runSpace.Close();
//create completed message
MessageBox.Show(@"Email migration is complete", @"Done");
Cursor.Current = Cursors.Default;
}