Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

powershell - open a mailbox to which I have full access

I can open my mailbox in exchange online with EWS and Powershell

$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService  
$service.Credentials = New-Object System.Net.NetworkCredential -ArgumentList $mail, $password
$service.URL = New-Object Uri("https://outlook.office365.com/EWS/Exchange.asmx")  
$view = New-Object Microsoft.Exchange.WebServices.Data.ItemView($numOfEmailsToRead, $index)
$folderview = New-Object Microsoft.Exchange.WebServices.Data.FolderView(10)
$folderview.PropertySet = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.Webservices.Data.BasePropertySet]::FirstClassProperties)
$folderview.PropertySet.Add([Microsoft.Exchange.Webservices.Data.FolderSchema]::DisplayName)
$folderview.Traversal = [Microsoft.Exchange.Webservices.Data.FolderTraversal]::Deep
$folderfindResults = $service.FindFolders([Microsoft.Exchange.Webservices.Data.WellKnownFolderName]::Inbox, $folderview)
$SearchFilterContainsSubString = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+ContainsSubstring([Microsoft.Exchange.WebServices.Data.ItemSchema]::Subject, $Paramerter)
$SearchFilterNot = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+Not($SearchFilterContainsSubString)
foreach ($InboxFolder in $folderfindResults) {

  $findResultsItems = $InboxFolder.findItems($SearchFilterNot,$view)}

How do I change the code to open a mailbox to which I have full access?

question from:https://stackoverflow.com/questions/65900750/open-a-mailbox-to-which-i-have-full-access

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In your example you need to use the Mailbox overload for Folder id so change

        $folderfindResults = $service.FindFolders([Microsoft.Exchange.Webservices.Data.WellKnownFolderName]::Inbox, $folderview)
    $SearchFilterContainsSubString = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+ContainsSubstring([Microsoft.Exchange.WebServices.Data.ItemSchema]::Subject, $Paramerter)
    $SearchFilterNot = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+Not($SearchFilterContainsSubString)
    foreach ($InboxFolder in $folderfindResults) {

    $findResultsItems = $InboxFolder.findItems($SearchFilterNot,$view)}

To

    $MailboxToAccess = "[email protected]"   
    $folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxToAccess)     
    $folderfindResults = $service.FindFolders($folderid, $folderview)
    $SearchFilterContainsSubString = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+ContainsSubstring([Microsoft.Exchange.WebServices.Data.ItemSchema]::Subject, $Paramerter)
    $SearchFilterNot = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+Not($SearchFilterContainsSubString)
    foreach ($InboxFolder in $folderfindResults) {

    $findResultsItems = $InboxFolder.findItems($SearchFilterNot,$view)}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...