Share via

Unable to find Outlook folders to remove from users Outlook

Alexis Crawford 201 Reputation points
2022-11-17T23:24:30.883+00:00

Hello,

The script is able to locate the specific Folder but is unable to delete it. I receive no error messages. Permission on Account in the production tenant is the same as the QA environment. I'm running this script with UPN credentials. This script in QA works as expected. I am unable to retrieve the UniqueFolderID whereas I can in the QA environment. Is there anything I can do to make it so the code can retrieve the UniqueFolderID?

All Outlook users are located in Exchange Online

#$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root, $_.Account)  
    $folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot, $_.Account)     
  
    try {  
        $inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service, $folderid)          
    }  
    catch {  
        Write-Host "Inbox cannot be found on $Account"  
        continue  
    }  

Thanks,

Exchange | Exchange Server | Development
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Glen Scales 4,446 Reputation points
    2022-11-20T22:32:49.83+00:00

    All Outlook users are located in Exchange Online

    What's your reason for using EWS to do this ? why not just use the Powershell graph sdk eg

    Get-MgUserMailFolder -MailFolderId MsgFolderRoot -UserId user@keyman

    its a lot simpler logic and supports all the different Auth scheme eg client_credentials etc, EWS is considered legacy and may go away at some point in the future the only reason to use it is if you have hybrid mailboxes or OnPrem.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.