我正在编写 ac# Windows Form 应用程序以将 Exchange 2010 邮箱迁移到 .pst 格式的服务器上的文件位置。我使用了 Powershell SDK (Runspace05) 中的示例来访问交换 cmdlet (Get-Mailbox) 并使用用户邮箱填充组合框,没有问题。
我遇到问题的部分是让 New-MailboxExportRequest cmdlet(执行导出的 cmdlet)运行,并能够返回它的对象并在列表框控件中显示它们。我错过了什么?在此先感谢您的帮助。
编码:
InitialSessionState iss = InitialSessionState.CreateDefault();
PSSnapInException warning;
iss.ImportPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", out warning);
using (Runspace myrunspace = RunspaceFactory.CreateRunspace(iss))
{
myrunspace.Open();
using (PowerShell powershell = PowerShell.Create())
{
var mailbox = cmbEmailUserName.Text;
var pstFile = txtFileSaveLocation.Text;
const int badLimit = 100; //can be increased in necessary
powershell.AddCommand("Microsoft.Exchange.Management.PowerShell.E2010\\New-MailboxExportRequest");
powershell.AddParameter("Mailbox", mailbox);
powershell.AddParameter("FilePath", pstFile);
powershell.Runspace = myrunspace;
Collection<PSObject> results = powershell.Invoke();
foreach (PSObject thisResult in results)
{
lstBoxStatus.Items.Add(thisResult);
}
myrunspace.Close();
}
}