[英]PowerShell script to download SharePoint attachments (Excel) with certain worksheet name
[英]I'm trying to Write a Powershell script that will download all attachments, When i it Downloads the first 10 attachments only
$password = ConvertTo-SecureString "xxx" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential "xxx@xxx.onmicrosoft.com",$password
$url = "https://outlook.office365.com/api/v1.0/me/messages"
$today = (Get-Date).AddDays(1).ToString("yyyy-MM-dd")
## Set date and query
$messageQuery = "" + $url + "?`$select=Id&`$filter=HasAttachments eq true and DateTimeReceived lt " + $today
$messages = Invoke-RestMethod $messageQuery -Credential $cred
## Loop through each results
foreach ($message in $messages.value)
{
# get attachments and save to file system
$query = $url + "/" + $message.Id + "/attachments"
$attachments = Invoke-RestMethod $query -Credential $cred
# in case of multiple attachments in email
foreach ($attachment in $attachments.value)
{
$attachment.Name
$path = "C:\path\" + $attachment.Name
$Content = [System.Convert]::FromBase64String($attachment.ContentBytes)
Set-Content -Path $path -Value $Content -Encoding Byte
}
}
运行此命令时,仅下载10个附件,然后停止。 我想弄清楚为什么它停止在10的原因,这样我才能继续下载整个收件箱。
我有同样的问题。 我认为它一次只能处理附件数量的X数量。 当我用这些行成功复制了附件后,我便从邮箱中删除了我的邮箱,因为收获附件后我不需要电子邮件了。
此代码(与我的代码的其余部分一起)每5分钟在Task Scheduler中运行一次,因此,如果在第一次运行中未捕获到所有邮件,便会对其进行处理,我猜在随后的运行中一次会处理10个。
如果($ DeleteEmail -eq“ Y”){
$ query2 = $ url +“ /” + $ message.Id
Invoke-RestMethod $ query2 -Credential $ Credentials -Method删除
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.