David-Barrett-MS / PowerShell-EWS-Scripts

A collection of PowerShell scripts that use EWS to perform actions against Exchange mailboxes
MIT License
118 stars 13 forks source link

What to do with uncopied files? #49

Closed Leni-Vietz closed 3 months ago

Leni-Vietz commented 7 months ago

Hi,

first of all - thank you for this marvellous script. Really helps with users without self-mailbox-control ;)

I'm copying a emails with the following command:

$src = "mailbox@domain.pl"
$dst = "mailbox2021@domain.pl"
$start = "12/31/2020"
$end = "01/01/2022"
.\Merge-MailboxFolder.ps1 -SourceMailbox $src -TargetMailbox $dst -OnlyItemsCreatedAfter $start -OnlyItemsCreatedBefore $end -SourceArchive -CreateTargetFolder -ProcessSubfolders -Office365 -OAuth -OAuthTenantId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

and I get the following:

08.02.2024 15:10:25 [MoveItems] [MoveItems]Moving from mailbox@domain.pl:\Folder nadrzędny magazynu informacji\Elementy wysłane to mailbox2021@domain.pl:
\Top of Information Store\Elementy wysłane
**08.02.2024 15:10:26 [MoveItems] 2534 items found; attempting to move**
08.02.2024 15:12:06 [RemoveProcessedItemsFromList] No results returned - assuming all items processed
(...)
08.02.2024 18:09:10 [Merge-MailboxFolder.ps1] Script finished in 02:59:03.7367093

No matter how many times I run the script there are still those 2534 items. Is there any workaround or parameters to add to deal with this? :)

David-Barrett-MS commented 7 months ago

I suspect the issue is that you are trying to copy from the archive mailbox of one user to the primary mailbox of another. Does it work from primary to primary? Note thatin this scenario, the authenticating account needs FullAccess permission to both mailboxes (or if impersonating the source, the source mailbox needs FullAccess permission to the target).

Leni-Vietz commented 7 months ago

The user has access FullAccess to mailbox2021@domain.pl and my account from which I run the scripts has access to both his and the 2021 archive.

Would it be a workaround to disable archiving of old messages for mailbox@domain.pl. Move the messages from archive of mailbox@domain.pl to the main mailbox and then move from non-archive to mailbox2021@domain.pl?

PS C:\Users\user\scripts> Get-EXOMailboxPermission mailbox2021@domain.pl

Identity        : Archiwum 2021 mailbox20221115084334
User            : NT AUTHORITY\SELF
AccessRights    : {FullAccess, ReadPermission}
IsInherited     : False
Deny            : False
InheritanceType : None

Identity        : Archiwum 2021 mailbox20221115084334
User            : NT AUTHORITY\SELF
AccessRights    : {FullAccess, ExternalAccount, ReadPermission}
IsInherited     : False
Deny            : False
InheritanceType : Descendents

Identity        : Archiwum 2021 mailbox20221115084334
User            : admin@domain.pl
AccessRights    : {FullAccess}
IsInherited     : False
Deny            : False
InheritanceType : All

Identity        : Archiwum 2021 mailbox20221115084334
User            : mailbox@domain.pl
AccessRights    : {FullAccess}
IsInherited     : False
Deny            : False
InheritanceType : All

PS C:\Users\user\scripts> Get-EXOMailboxPermission mailbox@domain.pl

Identity        : mailbox
User            : NT AUTHORITY\SELF
AccessRights    : {FullAccess, ReadPermission}
IsInherited     : False
Deny            : False
InheritanceType : All

Identity        : mailbox
User            : admin@domain.pl
AccessRights    : {FullAccess}
IsInherited     : False
Deny            : False
InheritanceType : All
Leni-Vietz commented 7 months ago

I also tried using the -Impersonate parameter and it didn't change the outcome.

David-Barrett-MS commented 3 months ago

I didn't get a chance to look into this until recently, but I can confirm that copying from one user's archive mailbox to another is not supported in EWS. You'll need to move items via a primary mailbox (so your workaround should work).