Export Exchange public folder to PST from PowerShellThere a easy way to move/change a public folder structure exchange server 2007?How do I restore Exchange 2003 public folder into 2007?Complete Public Folder Migration from Exchange 2007 to Exchange 2010Exchange 2007 - Public Folder Permissionsexport mailbox data from a mailbox to a .pst file (Exchange 2007)Can I export mailbox contents from an Exchange 2007 server if I install Outlook 2010 x64 on the same server?Restore deleted exchange 2007 public folder from backup .edb fileDecomissioning Exchange 2003 - Public folder instances still showing on Exchange 2003 serverHow to export specific folders from Exchange Mailbox' online archive to PSThow to backup/export office 365 email to pst in exchange hybrid environment?

Anabelian geometry ~ higher category theory

Was this character’s old age look CGI or make-up?

Why does the headset man not get on the tractor?

Is there anything special about -1 (0xFFFFFFFF) regarding ADC?

Why is a set not a partition of itself?

Is it possible to create different colors in rocket exhaust?

Can a tourist shoot a gun in the USA?

Will a coyote attack my dog on a leash while I'm on a hiking trail?

German characters on US-International keyboard layout

Does Lawful Interception of 4G / the proposed 5G provide a back door for hackers as well?

Why did the metro bus stop at each railway crossing, despite no warning indicating a train was coming?

What is the name of this Middle English letter?

Why was Thor doubtful about his worthiness to Mjolnir?

Frame adjustment for engine

Conditional probability - sum of dice is even given that at least one is a five

Solubility in different pressure conditions

Does SQL Server allow (make visible) DDL inside a transaction to the transaction prior to commit?

What's tha name for when you write multiple voices on same staff? And are there any cons?

How does emacs `shell-mode` know to prompt for sudo?

What to do if SUS scores contradict qualitative feedback?

Why do the lights go out when someone enters the dining room on this ship?

What information do scammers need to withdraw money from an account?

using `is` operator with value type tuples gives error

Is this a security concern for ubuntu users?



Export Exchange public folder to PST from PowerShell


There a easy way to move/change a public folder structure exchange server 2007?How do I restore Exchange 2003 public folder into 2007?Complete Public Folder Migration from Exchange 2007 to Exchange 2010Exchange 2007 - Public Folder Permissionsexport mailbox data from a mailbox to a .pst file (Exchange 2007)Can I export mailbox contents from an Exchange 2007 server if I install Outlook 2010 x64 on the same server?Restore deleted exchange 2007 public folder from backup .edb fileDecomissioning Exchange 2003 - Public folder instances still showing on Exchange 2003 serverHow to export specific folders from Exchange Mailbox' online archive to PSThow to backup/export office 365 email to pst in exchange hybrid environment?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















Is there a PowerShell cmdlet to export the contents of the public folder from Exchange 2007 into a PST on the network? I've got about 100 public folders that need archiving to different places on the network and would like to automate the process.



Also then need to be able to delete the public folder.



If not PowerShell, are there other utilities that can do the same from the command line?



Thanks, Rob.










share|improve this question






























    2















    Is there a PowerShell cmdlet to export the contents of the public folder from Exchange 2007 into a PST on the network? I've got about 100 public folders that need archiving to different places on the network and would like to automate the process.



    Also then need to be able to delete the public folder.



    If not PowerShell, are there other utilities that can do the same from the command line?



    Thanks, Rob.










    share|improve this question


























      2












      2








      2


      1






      Is there a PowerShell cmdlet to export the contents of the public folder from Exchange 2007 into a PST on the network? I've got about 100 public folders that need archiving to different places on the network and would like to automate the process.



      Also then need to be able to delete the public folder.



      If not PowerShell, are there other utilities that can do the same from the command line?



      Thanks, Rob.










      share|improve this question
















      Is there a PowerShell cmdlet to export the contents of the public folder from Exchange 2007 into a PST on the network? I've got about 100 public folders that need archiving to different places on the network and would like to automate the process.



      Also then need to be able to delete the public folder.



      If not PowerShell, are there other utilities that can do the same from the command line?



      Thanks, Rob.







      exchange-2007 powershell






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 14 '10 at 11:34









      dunxd

      7,1111973113




      7,1111973113










      asked Sep 14 '10 at 10:59









      Rob NicholsonRob Nicholson

      84361946




      84361946




















          2 Answers
          2






          active

          oldest

          votes


















          2














          I believe that without 3rd party tools, you'll need to use Outlook to export the public folders.






          share|improve this answer






























            4














            Even five years on I couldn't find any examples of how to do this, so I used Glen Scales' excellent EWS & PowerShell blog posts to cobble this together. It's tweaked for Exchange 2013 SP1, but the functionality is pretty basic so it should work on earlier versions too.



            Script to export old Public Folders to a share on the filesystem



            #Needs to run an account with PublishingAuthor rights to the PFs
            #
            # Kev Maitland 08/09/15

            $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://yourMailServer.yourDomain.local/PowerShell/ -Authentication Kerberos
            Import-PSSession $Session -AllowClobber

            $EWSServicePath = '\yourMailServerC$Program FilesMicrosoftExchangeWeb Services2.2Microsoft.Exchange.WebServices.dll'
            Import-Module $EWSServicePath

            #If necessary, grant Owner permissions to each folder the Public Folder hierarchy to ensure we export everything
            #Get-PublicFolder -Identity "" -Recurse | Add-PublicFolderClientPermission -AccessRights Owner -User "yourDomainHighlyPriveligedAccount"


            #Set some variables
            $ExchVer = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1
            $ewsUrl = "https://mail.yourDomain.co.uk/EWS/Exchange.asmx"
            $upnExtension = "yourDomain.local"
            $smtpServer = "yourMailServer.yourDomain.local"
            $pFRootPath = ""
            $outputPathRoot = "\HV05PF"

            #Prepare some functions
            function FolderIdFromPath From Glen Scales http://gsexdev.blogspot.co.uk/2013/08/public-folder-ews-how-to-rollup-part-1.html
            param ($FolderPath = "$( throw 'Folder Path is a mandatory Parameter' )")
            process
            ## Find and Bind to Folder based on Path
            #Define the path to search should be seperated with
            #Bind to the MSGFolder Root
            $folderId = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::PublicFoldersRoot)
            $tfTargetFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderId)
            #Split the Search path into an array
            $fldArray = $FolderPath.Split("")
            #Loop through the Split Array and do a Search for each level of folder
            for ($lint = 1; $lint -lt $fldArray.Length; $lint++)
            #Perform search based on the displayname of each folder level
            $fvFolderView = new-object Microsoft.Exchange.WebServices.Data.FolderView(1)
            $SfSearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName,$fldArray[$lint])
            $findFolderResults = $service.FindFolders($tfTargetFolder.Id,$SfSearchFilter,$fvFolderView)
            if ($findFolderResults.TotalCount -gt 0)
            foreach($folder in $findFolderResults.Folders)
            $tfTargetFolder = $folder


            else
            "Error Folder Not Found"
            $tfTargetFolder = $null
            break


            if($tfTargetFolder -ne $null)
            return $tfTargetFolder.Id.UniqueId.ToString()



            function getPublicFolderViaEws([string]$publicFolderPath)
            $folderId = new-object Microsoft.Exchange.WebServices.Data.FolderId(FolderIdFromPath -FolderPath $publicFolderPath)
            [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderId)


            #Get set up using the current user's security context
            $windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
            $sidbind = "LDAP://<SID=" + $windowsIdentity.user.Value.ToString() + ">"
            $aceuser = [ADSI]$sidbind
            $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($exchver)
            $service.Url = $ewsUrl
            $service.AutodiscoverUrl($aceuser.mail.ToString())

            $propertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties) #Get all the default properties of the items in the Public Folders
            $propertySet.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::MimeContent) #Add the MimeContent property too, so that we can send it directy to the filestream later



            foreach ($folderPS in Get-PublicFolder -Recurse)
            New-Item -Path "$outputPathRoot$($folderPS.ParentPath)$($folderPS.Name)" -ItemType Directory #Make a filesystem folder to match the Public Folder hierarchy
            $folderEws = getPublicFolderViaEws -publicFolderPath "$($folderPS.ParentPath)$($folderPS.Name)".Replace("\","") #Bodge the odd occasion where we end up with two backslashes in a folder name
            $itemView = New-Object Microsoft.Exchange.WebServices.Data.ItemView(10)
            $foundItems = $null
            do
            $foundItems = $service.FindItems($folderEws.Id,$itemView) #Get the first batch of objects in the current Public Folder
            [Void]$service.LoadPropertiesForItems($foundItems,$propertySet) #Load the properties we specified earlier
            $i = $null
            foreach($email in $foundItems.Items)",''))$i") #Remove all illegal filesystem characters from the subject of the e-mail. If the result already exists on the filesystem, add an incremented number until it is unique (so that we don't accidentally overwrite e-mail threads)
            $i++

            [System.IO.File]::WriteAllBytes("$outputPathRoot$($folderPS.ParentPath)$($folderPS.Name)$($email.Subject.Replace(":",'').Replace("/",'').Replace("",'').Replace("*",'').Replace("?",'').Replace("<",'').Replace(">",'').Replace("
            $itemView.Offset += $foundItems.Items.Count #Get ready to process the next batch of e-mails in the Public Folder

            while($foundItems.MoreAvailable -eq $true)






            share|improve this answer























              Your Answer








              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "2"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f180916%2fexport-exchange-public-folder-to-pst-from-powershell%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              I believe that without 3rd party tools, you'll need to use Outlook to export the public folders.






              share|improve this answer



























                2














                I believe that without 3rd party tools, you'll need to use Outlook to export the public folders.






                share|improve this answer

























                  2












                  2








                  2







                  I believe that without 3rd party tools, you'll need to use Outlook to export the public folders.






                  share|improve this answer













                  I believe that without 3rd party tools, you'll need to use Outlook to export the public folders.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 24 '10 at 23:32









                  James BJames B

                  362




                  362























                      4














                      Even five years on I couldn't find any examples of how to do this, so I used Glen Scales' excellent EWS & PowerShell blog posts to cobble this together. It's tweaked for Exchange 2013 SP1, but the functionality is pretty basic so it should work on earlier versions too.



                      Script to export old Public Folders to a share on the filesystem



                      #Needs to run an account with PublishingAuthor rights to the PFs
                      #
                      # Kev Maitland 08/09/15

                      $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://yourMailServer.yourDomain.local/PowerShell/ -Authentication Kerberos
                      Import-PSSession $Session -AllowClobber

                      $EWSServicePath = '\yourMailServerC$Program FilesMicrosoftExchangeWeb Services2.2Microsoft.Exchange.WebServices.dll'
                      Import-Module $EWSServicePath

                      #If necessary, grant Owner permissions to each folder the Public Folder hierarchy to ensure we export everything
                      #Get-PublicFolder -Identity "" -Recurse | Add-PublicFolderClientPermission -AccessRights Owner -User "yourDomainHighlyPriveligedAccount"


                      #Set some variables
                      $ExchVer = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1
                      $ewsUrl = "https://mail.yourDomain.co.uk/EWS/Exchange.asmx"
                      $upnExtension = "yourDomain.local"
                      $smtpServer = "yourMailServer.yourDomain.local"
                      $pFRootPath = ""
                      $outputPathRoot = "\HV05PF"

                      #Prepare some functions
                      function FolderIdFromPath From Glen Scales http://gsexdev.blogspot.co.uk/2013/08/public-folder-ews-how-to-rollup-part-1.html
                      param ($FolderPath = "$( throw 'Folder Path is a mandatory Parameter' )")
                      process
                      ## Find and Bind to Folder based on Path
                      #Define the path to search should be seperated with
                      #Bind to the MSGFolder Root
                      $folderId = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::PublicFoldersRoot)
                      $tfTargetFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderId)
                      #Split the Search path into an array
                      $fldArray = $FolderPath.Split("")
                      #Loop through the Split Array and do a Search for each level of folder
                      for ($lint = 1; $lint -lt $fldArray.Length; $lint++)
                      #Perform search based on the displayname of each folder level
                      $fvFolderView = new-object Microsoft.Exchange.WebServices.Data.FolderView(1)
                      $SfSearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName,$fldArray[$lint])
                      $findFolderResults = $service.FindFolders($tfTargetFolder.Id,$SfSearchFilter,$fvFolderView)
                      if ($findFolderResults.TotalCount -gt 0)
                      foreach($folder in $findFolderResults.Folders)
                      $tfTargetFolder = $folder


                      else
                      "Error Folder Not Found"
                      $tfTargetFolder = $null
                      break


                      if($tfTargetFolder -ne $null)
                      return $tfTargetFolder.Id.UniqueId.ToString()



                      function getPublicFolderViaEws([string]$publicFolderPath)
                      $folderId = new-object Microsoft.Exchange.WebServices.Data.FolderId(FolderIdFromPath -FolderPath $publicFolderPath)
                      [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderId)


                      #Get set up using the current user's security context
                      $windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
                      $sidbind = "LDAP://<SID=" + $windowsIdentity.user.Value.ToString() + ">"
                      $aceuser = [ADSI]$sidbind
                      $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($exchver)
                      $service.Url = $ewsUrl
                      $service.AutodiscoverUrl($aceuser.mail.ToString())

                      $propertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties) #Get all the default properties of the items in the Public Folders
                      $propertySet.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::MimeContent) #Add the MimeContent property too, so that we can send it directy to the filestream later



                      foreach ($folderPS in Get-PublicFolder -Recurse)
                      New-Item -Path "$outputPathRoot$($folderPS.ParentPath)$($folderPS.Name)" -ItemType Directory #Make a filesystem folder to match the Public Folder hierarchy
                      $folderEws = getPublicFolderViaEws -publicFolderPath "$($folderPS.ParentPath)$($folderPS.Name)".Replace("\","") #Bodge the odd occasion where we end up with two backslashes in a folder name
                      $itemView = New-Object Microsoft.Exchange.WebServices.Data.ItemView(10)
                      $foundItems = $null
                      do
                      $foundItems = $service.FindItems($folderEws.Id,$itemView) #Get the first batch of objects in the current Public Folder
                      [Void]$service.LoadPropertiesForItems($foundItems,$propertySet) #Load the properties we specified earlier
                      $i = $null
                      foreach($email in $foundItems.Items)",''))$i") #Remove all illegal filesystem characters from the subject of the e-mail. If the result already exists on the filesystem, add an incremented number until it is unique (so that we don't accidentally overwrite e-mail threads)
                      $i++

                      [System.IO.File]::WriteAllBytes("$outputPathRoot$($folderPS.ParentPath)$($folderPS.Name)$($email.Subject.Replace(":",'').Replace("/",'').Replace("",'').Replace("*",'').Replace("?",'').Replace("<",'').Replace(">",'').Replace("
                      $itemView.Offset += $foundItems.Items.Count #Get ready to process the next batch of e-mails in the Public Folder

                      while($foundItems.MoreAvailable -eq $true)






                      share|improve this answer



























                        4














                        Even five years on I couldn't find any examples of how to do this, so I used Glen Scales' excellent EWS & PowerShell blog posts to cobble this together. It's tweaked for Exchange 2013 SP1, but the functionality is pretty basic so it should work on earlier versions too.



                        Script to export old Public Folders to a share on the filesystem



                        #Needs to run an account with PublishingAuthor rights to the PFs
                        #
                        # Kev Maitland 08/09/15

                        $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://yourMailServer.yourDomain.local/PowerShell/ -Authentication Kerberos
                        Import-PSSession $Session -AllowClobber

                        $EWSServicePath = '\yourMailServerC$Program FilesMicrosoftExchangeWeb Services2.2Microsoft.Exchange.WebServices.dll'
                        Import-Module $EWSServicePath

                        #If necessary, grant Owner permissions to each folder the Public Folder hierarchy to ensure we export everything
                        #Get-PublicFolder -Identity "" -Recurse | Add-PublicFolderClientPermission -AccessRights Owner -User "yourDomainHighlyPriveligedAccount"


                        #Set some variables
                        $ExchVer = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1
                        $ewsUrl = "https://mail.yourDomain.co.uk/EWS/Exchange.asmx"
                        $upnExtension = "yourDomain.local"
                        $smtpServer = "yourMailServer.yourDomain.local"
                        $pFRootPath = ""
                        $outputPathRoot = "\HV05PF"

                        #Prepare some functions
                        function FolderIdFromPath From Glen Scales http://gsexdev.blogspot.co.uk/2013/08/public-folder-ews-how-to-rollup-part-1.html
                        param ($FolderPath = "$( throw 'Folder Path is a mandatory Parameter' )")
                        process
                        ## Find and Bind to Folder based on Path
                        #Define the path to search should be seperated with
                        #Bind to the MSGFolder Root
                        $folderId = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::PublicFoldersRoot)
                        $tfTargetFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderId)
                        #Split the Search path into an array
                        $fldArray = $FolderPath.Split("")
                        #Loop through the Split Array and do a Search for each level of folder
                        for ($lint = 1; $lint -lt $fldArray.Length; $lint++)
                        #Perform search based on the displayname of each folder level
                        $fvFolderView = new-object Microsoft.Exchange.WebServices.Data.FolderView(1)
                        $SfSearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName,$fldArray[$lint])
                        $findFolderResults = $service.FindFolders($tfTargetFolder.Id,$SfSearchFilter,$fvFolderView)
                        if ($findFolderResults.TotalCount -gt 0)
                        foreach($folder in $findFolderResults.Folders)
                        $tfTargetFolder = $folder


                        else
                        "Error Folder Not Found"
                        $tfTargetFolder = $null
                        break


                        if($tfTargetFolder -ne $null)
                        return $tfTargetFolder.Id.UniqueId.ToString()



                        function getPublicFolderViaEws([string]$publicFolderPath)
                        $folderId = new-object Microsoft.Exchange.WebServices.Data.FolderId(FolderIdFromPath -FolderPath $publicFolderPath)
                        [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderId)


                        #Get set up using the current user's security context
                        $windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
                        $sidbind = "LDAP://<SID=" + $windowsIdentity.user.Value.ToString() + ">"
                        $aceuser = [ADSI]$sidbind
                        $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($exchver)
                        $service.Url = $ewsUrl
                        $service.AutodiscoverUrl($aceuser.mail.ToString())

                        $propertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties) #Get all the default properties of the items in the Public Folders
                        $propertySet.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::MimeContent) #Add the MimeContent property too, so that we can send it directy to the filestream later



                        foreach ($folderPS in Get-PublicFolder -Recurse)
                        New-Item -Path "$outputPathRoot$($folderPS.ParentPath)$($folderPS.Name)" -ItemType Directory #Make a filesystem folder to match the Public Folder hierarchy
                        $folderEws = getPublicFolderViaEws -publicFolderPath "$($folderPS.ParentPath)$($folderPS.Name)".Replace("\","") #Bodge the odd occasion where we end up with two backslashes in a folder name
                        $itemView = New-Object Microsoft.Exchange.WebServices.Data.ItemView(10)
                        $foundItems = $null
                        do
                        $foundItems = $service.FindItems($folderEws.Id,$itemView) #Get the first batch of objects in the current Public Folder
                        [Void]$service.LoadPropertiesForItems($foundItems,$propertySet) #Load the properties we specified earlier
                        $i = $null
                        foreach($email in $foundItems.Items)",''))$i") #Remove all illegal filesystem characters from the subject of the e-mail. If the result already exists on the filesystem, add an incremented number until it is unique (so that we don't accidentally overwrite e-mail threads)
                        $i++

                        [System.IO.File]::WriteAllBytes("$outputPathRoot$($folderPS.ParentPath)$($folderPS.Name)$($email.Subject.Replace(":",'').Replace("/",'').Replace("",'').Replace("*",'').Replace("?",'').Replace("<",'').Replace(">",'').Replace("
                        $itemView.Offset += $foundItems.Items.Count #Get ready to process the next batch of e-mails in the Public Folder

                        while($foundItems.MoreAvailable -eq $true)






                        share|improve this answer

























                          4












                          4








                          4







                          Even five years on I couldn't find any examples of how to do this, so I used Glen Scales' excellent EWS & PowerShell blog posts to cobble this together. It's tweaked for Exchange 2013 SP1, but the functionality is pretty basic so it should work on earlier versions too.



                          Script to export old Public Folders to a share on the filesystem



                          #Needs to run an account with PublishingAuthor rights to the PFs
                          #
                          # Kev Maitland 08/09/15

                          $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://yourMailServer.yourDomain.local/PowerShell/ -Authentication Kerberos
                          Import-PSSession $Session -AllowClobber

                          $EWSServicePath = '\yourMailServerC$Program FilesMicrosoftExchangeWeb Services2.2Microsoft.Exchange.WebServices.dll'
                          Import-Module $EWSServicePath

                          #If necessary, grant Owner permissions to each folder the Public Folder hierarchy to ensure we export everything
                          #Get-PublicFolder -Identity "" -Recurse | Add-PublicFolderClientPermission -AccessRights Owner -User "yourDomainHighlyPriveligedAccount"


                          #Set some variables
                          $ExchVer = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1
                          $ewsUrl = "https://mail.yourDomain.co.uk/EWS/Exchange.asmx"
                          $upnExtension = "yourDomain.local"
                          $smtpServer = "yourMailServer.yourDomain.local"
                          $pFRootPath = ""
                          $outputPathRoot = "\HV05PF"

                          #Prepare some functions
                          function FolderIdFromPath From Glen Scales http://gsexdev.blogspot.co.uk/2013/08/public-folder-ews-how-to-rollup-part-1.html
                          param ($FolderPath = "$( throw 'Folder Path is a mandatory Parameter' )")
                          process
                          ## Find and Bind to Folder based on Path
                          #Define the path to search should be seperated with
                          #Bind to the MSGFolder Root
                          $folderId = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::PublicFoldersRoot)
                          $tfTargetFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderId)
                          #Split the Search path into an array
                          $fldArray = $FolderPath.Split("")
                          #Loop through the Split Array and do a Search for each level of folder
                          for ($lint = 1; $lint -lt $fldArray.Length; $lint++)
                          #Perform search based on the displayname of each folder level
                          $fvFolderView = new-object Microsoft.Exchange.WebServices.Data.FolderView(1)
                          $SfSearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName,$fldArray[$lint])
                          $findFolderResults = $service.FindFolders($tfTargetFolder.Id,$SfSearchFilter,$fvFolderView)
                          if ($findFolderResults.TotalCount -gt 0)
                          foreach($folder in $findFolderResults.Folders)
                          $tfTargetFolder = $folder


                          else
                          "Error Folder Not Found"
                          $tfTargetFolder = $null
                          break


                          if($tfTargetFolder -ne $null)
                          return $tfTargetFolder.Id.UniqueId.ToString()



                          function getPublicFolderViaEws([string]$publicFolderPath)
                          $folderId = new-object Microsoft.Exchange.WebServices.Data.FolderId(FolderIdFromPath -FolderPath $publicFolderPath)
                          [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderId)


                          #Get set up using the current user's security context
                          $windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
                          $sidbind = "LDAP://<SID=" + $windowsIdentity.user.Value.ToString() + ">"
                          $aceuser = [ADSI]$sidbind
                          $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($exchver)
                          $service.Url = $ewsUrl
                          $service.AutodiscoverUrl($aceuser.mail.ToString())

                          $propertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties) #Get all the default properties of the items in the Public Folders
                          $propertySet.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::MimeContent) #Add the MimeContent property too, so that we can send it directy to the filestream later



                          foreach ($folderPS in Get-PublicFolder -Recurse)
                          New-Item -Path "$outputPathRoot$($folderPS.ParentPath)$($folderPS.Name)" -ItemType Directory #Make a filesystem folder to match the Public Folder hierarchy
                          $folderEws = getPublicFolderViaEws -publicFolderPath "$($folderPS.ParentPath)$($folderPS.Name)".Replace("\","") #Bodge the odd occasion where we end up with two backslashes in a folder name
                          $itemView = New-Object Microsoft.Exchange.WebServices.Data.ItemView(10)
                          $foundItems = $null
                          do
                          $foundItems = $service.FindItems($folderEws.Id,$itemView) #Get the first batch of objects in the current Public Folder
                          [Void]$service.LoadPropertiesForItems($foundItems,$propertySet) #Load the properties we specified earlier
                          $i = $null
                          foreach($email in $foundItems.Items)",''))$i") #Remove all illegal filesystem characters from the subject of the e-mail. If the result already exists on the filesystem, add an incremented number until it is unique (so that we don't accidentally overwrite e-mail threads)
                          $i++

                          [System.IO.File]::WriteAllBytes("$outputPathRoot$($folderPS.ParentPath)$($folderPS.Name)$($email.Subject.Replace(":",'').Replace("/",'').Replace("",'').Replace("*",'').Replace("?",'').Replace("<",'').Replace(">",'').Replace("
                          $itemView.Offset += $foundItems.Items.Count #Get ready to process the next batch of e-mails in the Public Folder

                          while($foundItems.MoreAvailable -eq $true)






                          share|improve this answer













                          Even five years on I couldn't find any examples of how to do this, so I used Glen Scales' excellent EWS & PowerShell blog posts to cobble this together. It's tweaked for Exchange 2013 SP1, but the functionality is pretty basic so it should work on earlier versions too.



                          Script to export old Public Folders to a share on the filesystem



                          #Needs to run an account with PublishingAuthor rights to the PFs
                          #
                          # Kev Maitland 08/09/15

                          $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://yourMailServer.yourDomain.local/PowerShell/ -Authentication Kerberos
                          Import-PSSession $Session -AllowClobber

                          $EWSServicePath = '\yourMailServerC$Program FilesMicrosoftExchangeWeb Services2.2Microsoft.Exchange.WebServices.dll'
                          Import-Module $EWSServicePath

                          #If necessary, grant Owner permissions to each folder the Public Folder hierarchy to ensure we export everything
                          #Get-PublicFolder -Identity "" -Recurse | Add-PublicFolderClientPermission -AccessRights Owner -User "yourDomainHighlyPriveligedAccount"


                          #Set some variables
                          $ExchVer = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1
                          $ewsUrl = "https://mail.yourDomain.co.uk/EWS/Exchange.asmx"
                          $upnExtension = "yourDomain.local"
                          $smtpServer = "yourMailServer.yourDomain.local"
                          $pFRootPath = ""
                          $outputPathRoot = "\HV05PF"

                          #Prepare some functions
                          function FolderIdFromPath From Glen Scales http://gsexdev.blogspot.co.uk/2013/08/public-folder-ews-how-to-rollup-part-1.html
                          param ($FolderPath = "$( throw 'Folder Path is a mandatory Parameter' )")
                          process
                          ## Find and Bind to Folder based on Path
                          #Define the path to search should be seperated with
                          #Bind to the MSGFolder Root
                          $folderId = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::PublicFoldersRoot)
                          $tfTargetFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderId)
                          #Split the Search path into an array
                          $fldArray = $FolderPath.Split("")
                          #Loop through the Split Array and do a Search for each level of folder
                          for ($lint = 1; $lint -lt $fldArray.Length; $lint++)
                          #Perform search based on the displayname of each folder level
                          $fvFolderView = new-object Microsoft.Exchange.WebServices.Data.FolderView(1)
                          $SfSearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName,$fldArray[$lint])
                          $findFolderResults = $service.FindFolders($tfTargetFolder.Id,$SfSearchFilter,$fvFolderView)
                          if ($findFolderResults.TotalCount -gt 0)
                          foreach($folder in $findFolderResults.Folders)
                          $tfTargetFolder = $folder


                          else
                          "Error Folder Not Found"
                          $tfTargetFolder = $null
                          break


                          if($tfTargetFolder -ne $null)
                          return $tfTargetFolder.Id.UniqueId.ToString()



                          function getPublicFolderViaEws([string]$publicFolderPath)
                          $folderId = new-object Microsoft.Exchange.WebServices.Data.FolderId(FolderIdFromPath -FolderPath $publicFolderPath)
                          [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderId)


                          #Get set up using the current user's security context
                          $windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
                          $sidbind = "LDAP://<SID=" + $windowsIdentity.user.Value.ToString() + ">"
                          $aceuser = [ADSI]$sidbind
                          $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($exchver)
                          $service.Url = $ewsUrl
                          $service.AutodiscoverUrl($aceuser.mail.ToString())

                          $propertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties) #Get all the default properties of the items in the Public Folders
                          $propertySet.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::MimeContent) #Add the MimeContent property too, so that we can send it directy to the filestream later



                          foreach ($folderPS in Get-PublicFolder -Recurse)
                          New-Item -Path "$outputPathRoot$($folderPS.ParentPath)$($folderPS.Name)" -ItemType Directory #Make a filesystem folder to match the Public Folder hierarchy
                          $folderEws = getPublicFolderViaEws -publicFolderPath "$($folderPS.ParentPath)$($folderPS.Name)".Replace("\","") #Bodge the odd occasion where we end up with two backslashes in a folder name
                          $itemView = New-Object Microsoft.Exchange.WebServices.Data.ItemView(10)
                          $foundItems = $null
                          do
                          $foundItems = $service.FindItems($folderEws.Id,$itemView) #Get the first batch of objects in the current Public Folder
                          [Void]$service.LoadPropertiesForItems($foundItems,$propertySet) #Load the properties we specified earlier
                          $i = $null
                          foreach($email in $foundItems.Items)",''))$i") #Remove all illegal filesystem characters from the subject of the e-mail. If the result already exists on the filesystem, add an incremented number until it is unique (so that we don't accidentally overwrite e-mail threads)
                          $i++

                          [System.IO.File]::WriteAllBytes("$outputPathRoot$($folderPS.ParentPath)$($folderPS.Name)$($email.Subject.Replace(":",'').Replace("/",'').Replace("",'').Replace("*",'').Replace("?",'').Replace("<",'').Replace(">",'').Replace("
                          $itemView.Offset += $foundItems.Items.Count #Get ready to process the next batch of e-mails in the Public Folder

                          while($foundItems.MoreAvailable -eq $true)







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Sep 14 '15 at 9:20









                          Kev MaitlandKev Maitland

                          412




                          412



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Server Fault!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f180916%2fexport-exchange-public-folder-to-pst-from-powershell%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

                              Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

                              What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company