저는 PowerShell을 처음 사용하고 있으며 공유 편지함에 읽지 않은 메일이 있는지 확인하기 위해 현재 스크립트 작업을하고 있습니다. 현재 FindItems()
방법으로 메일을 다시 보내려고합니다.EWS로 읽지 않은 교환 메일 수를 확인하십시오.
[int]$nb_unread = 0
[string]$email = "[email protected]"
[string]$Msg = ""
[int]$Code = 0
[string]$err = ""
Try
{
Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"
$ews = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013)
$ews.Credentials = New-Object Net.NetworkCredential('user', 'password')
$ews.AutodiscoverUrl($email, {$true})
$inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($ews,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)
$view = new-object Microsoft.Exchange.WebServices.Data.ItemView(10)
$mailItems = $inbox.FindItems($view)
$mails | ForEach {$_.Load()}
foreach($mail in $mails)
{
if($mail.isread -eq $false)
{
nb_unread += 1
}
}
if (nb_unread -eq 0)
{
$Msg = "OK;No unread mail."
}
else
{
$Msg = ("NOOK;Unread mails : " -f $nb_unread)
}
}
Catch
{
$Code = 2
$Msg = ("CRITICAL: erreur(s) d'execution du script : {0}" -f $err)
}
내 스크립트는 '$ mailItems = $ inbox.FindItems ($보기)'라인을 실행할 때이 오류가 발생했습니다 : 다음은 내 코드입니다.
Exception lors de l'appel de «FindItems» avec «1» argument(s): «The request failed. Le serveur distant a retourné une
erreur: (501) Non implémenté.»
Au caractère Ligne:16 : 5
+ $mailItems = $inbox.FindItems($view)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ServiceRequestException
거친 영어 번역
Exception when calling "FindItems" with "1" argument (s): "The request failed. The remote server returned an error: (501) Not implemented.
At Line:16 Char:5
+ $ mailItems = $inbox.FindItems ($ view)
+ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo: NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId: ServiceRequestException
그리고 당신의 문제는 정확히 무엇입니까? 이 코드는 어떻게 작동하지 않습니까? 거대한 try 블록과 catch 블록이 없으므로 구문 오류가 발생합니다. 코드가 빈 catch에서 자동으로 오류가 발생합니까? – Matt
글쎄, FindItem을 실행할 때 스크립트가 충돌합니다. 내 메시지가 오류로 업데이트됩니다. – Aurelien