简体   繁体   English

将邮箱从Exchange Server导出到PST文件

[英]export mailbox from Exchange Server to a PST file

I trying to export a mailbox (of any user) from a Exchange 2010 Server to a PST file. 我试图将(任何用户的)邮箱从Exchange 2010服务器导出到PST文件。 What is the best way to archive this? 存档的最佳方法是什么?

First I was looking at the COM-Interop model. 首先,我正在研究COM-Interop模型。 But this seems just to be able to export the Mailbox of the user that is currently logged in into Outlook. 但这似乎只是能够导出当前登录到Outlook的用户的邮箱。 Or am I missing something there? 还是我在那里缺少什么? I tried this: 我尝试了这个:

Dim app As New Outlook.Application()
Dim ns As Outlook.NameSpace = app.GetNamespace("MAPI")
ns.AddStore("C:\backup.pst")
Dim backupFolder As Outlook.MAPIFolder = ns.Session.Folders.GetLast()
Dim selectedMailBox As Outlook.MAPIFolder = ns.Folders("mymail@company.com") 'NOT Working
selectedMailBox.CopyTo(backupFolder)
ns.RemoveStore(backupFolder)

Later I found this PowerShell function: New-MailboxExportRequest Sadly I can't find a way to call this from .NET. 后来我发现了这个PowerShell函数: New-MailboxExportRequest很遗憾,我找不到从.NET调用此方法的方法。 Is there any possibility to call it from .NET? 是否可以从.NET调用它?

Or do I need to use any other library to export files from Exchange? 还是我需要使用任何其他库从Exchange导出文件? ( Maybe use POP3 to get all Mails and convert them to PST? ) 也许使用POP3来获取所有邮件并将其转换为PST?

You can use Redemption for that - run your code as a domain user who can access the mailboxes in question and call RDOSession.LogonExchangeMailbox . 您可以为此使用Redemption-以域用户身份运行代码,该用户可以访问有问题的邮箱并调用RDOSession.LogonExchangeMailbox You can then open other users' mailboxes using RDOSession.Stores.GetSharedMailbox . 然后,您可以使用RDOSession.Stores.GetSharedMailbox打开其他用户的邮箱。 Once you have the RDOStore object, you will be able to access all of the folders and messages starting with RDOStore.IPMRootFolder . 一旦有了RDOStore对象,就可以访问以RDOStore.IPMRootFolder开头的所有文件夹和消息。

To copy to a PST store, you can add a new or existing PST file using RDOSession.Stores.AddPstStore . 要复制到PST存储,可以使用RDOSession.Stores.AddPstStore添加新的或现有的PST文件。

To copy all the folders, using something like the following 使用以下方法复制所有文件夹

foreach (RDOFolder sourceFolder in ExchangeStore.IPMRootFolder.Folders)
{
  sourceFolder.CopyTo(PstStore.IPMRootFolder);
}

You can execute Powershell commands in C# using System.Management.Automation and System.Management.Automation.Runspaces. 您可以使用System.Management.Automation和System.Management.Automation.Runspaces在C#中执行Powershell命令。

a very limited example: 一个非常有限的例子:

int GetMiliseconds()
{
    using (var ps = System.Management.Automation.PowerShell.Create())
    {
        var cmd = new System.Management.Automation.Runspaces.Command("Get-Date");
        ps.Commands.AddCommand(cmd);
        var result = ps.Invoke();
        return result != null && result.Any() ? result.First().Members["Millisecond"].Value as Int32? ?? 0 : 0;
    }
}  

The trickiest part is that result always comes back as ICollection<PSObject> , and you have to keep your eyes open for exceptions thrown and null values all the time. 最棘手的部分是,结果总是以ICollection<PSObject> ,并且您必须ICollection<PSObject>异常抛出和null值。

which exchange server? 哪个交换服务器? In exchange server 2013, you have to first give rights for this role as even the administrator doesn't have them. 在Exchange Server 2013中,您必须首先为该角色授予权限,因为即使管理员没有权限。 Open Windows Power-Shell with administrative privileges the do this command: 使用管理特权打开Windows Power-Shell,请执行以下命令:

New-ManagementRoleAssignment –Role “Mailbox Import Export” –User "username" New-ManagementRoleAssignment –角色“邮箱导入导出” –用户“用户名”

(REPLACE "username" WITH THE USERNAME). (用用户名替换“用户名”)。

Create a shared network folder and remember the path as in \\"SERVER-NAME"\\"SHAREDFOLDERNAME". 创建一个共享的网络文件夹,并记住路径,如\\“ SERVER-NAME” \\“ SHAREDFOLDERNAME”。

Replace "SERVER-NAME" with your server name and "SHAREDFOLDERNAME" with your specific shared folder name. 用您的服务器名称替换“ SERVER-NAME”,并用您的特定共享文件夹名称替换“ SHAREDFOLDERNAME”。 On Exchange Server Management shell (Command Line Interface),use the command Get-Mailbox to get all the mailboxes you have in your exchange server and from there, you can choose the mailbox whose .pst file you want to export. 在Exchange Server命令行管理程序外壳程序(命令行界面)上,使用命令Get-Mailbox获取您在交换服务器中拥有的所有邮箱,然后从那里选择要导出其.pst文件的邮箱。 Next, on the CLI, type: 接下来,在CLI上键入:

New-MailboxExportRequest –Mailbox "USERNAME" –FilePath \\"SERVER-NAME"\\"SHAREDFOLDERNAME"\\"PSTFILENAME".pst New-MailboxExportRequest –邮箱“ USERNAME” –FilePath \\“服务器名称” \\“ SHAREDFOLDERNAME” \\“ PSTFILENAME” .pst

Again remember to replace "SERVER-NAME" and "USERNAME" with your servername and the specific mailbox's username to be exported otherwise, an error will occur. 再次记住要用您的服务器名和要导出的特定邮箱的用户名替换“ SERVER-NAME”和“ USERNAME”,否则将发生错误。 Replace "PSTFILENAME" with the name as you would like to save your file. 用您想要保存文件的名称替换“ PSTFILENAME”。 After then, you can check the shared folder and you'll notice the size of the file increasing or use the command: Get-MailboxExportRequest -Mailbox "SPECIFICUSERNAME" | 之后,您可以检查共享文件夹,并且会注意到文件大小增加或使用以下命令:Get-MailboxExportRequest -Mailbox“ SPECIFICUSERNAME” | format-table -wrap -autosize 格式表-换行-自动调整大小

to view if the process is done or not. 查看该过程是否完成。 if it's done it'll indicate as "Completed" in the status column. 如果完成,它将在状态列中指示为“已完成”。 If not, it'll indicate "queued". 如果不是,它将指示“已排队”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM