【发布时间】:2014-05-15 14:14:39
【问题描述】:
我有一个连接到 Outlook 的 Sharepoint 目录。每天都会有一个 csv 发布到这个目录,我可以从 Outlook 中获取它,而不是导航到 Sharepoint 站点。
我需要编写一个 Powershell 脚本,该脚本将从 Outlook 中的 Sharepoint 列表中提取最新文件,并将其转储到本地目录中。
我无法直接从 Sharepoint 中提取,因为我没有管理员权限。我也不能直接从提供给 Sharepoint 的目录中提取,因为我没有该目录的权限。这必须通过 Outlook 完成。
我认为我可以像从 Outlook 中提取电子邮件附件一样执行此操作,但我的脚本不起作用:
#file path
$filepath = "I:\WriteToHere"
$account = "mail@company.com"
#set outlook to open
$o = New-Object -comobject outlook.application
$n = $o.GetNamespace(“MAPI”)
$Account = $n.Folders | ? { $_.Name -eq $account };
$Inbox = $Account.Folders | ? { $_.Name -match 'Root Folder' };
$Data = $Inbox.Folders | ? { $_.Name -match 'Sub1' };
$Year = $Data.Folders | ? { $_.Name -match 'Sub2' };
$Month = $Year.Folders | ? { $_.Name -match 'Sub3' };
$email = $Month.Items| Sort-Object ReceivedTime -Descending | Select-Object -First 1
# Log the email we are looking for, and mention attachments if they exist.
Write-Output "Last email received at $($email.receivedtime), attached file(s) are: (if any)"
$email.attachments|%{Write-Output $_.filename}
# If the email has at least one attachment, save them to the filepath.
If($email.attachments.count -gt 0){
$email.attachments|%{$_.saveasfile((join-path $filepath $_.filename))}
} else {
Write-Output "Latest email at $($email.receivedtime) has no attachments!"
}
注意 - 我收件箱中的 Sharepoint 项目只是 csv 文件。它们不是带附件的消息。
我认为我不能像对待电子邮件一样对待这些 Sharepoint 项目。我会四处寻找解决方案,但我想发布这个以防有人能指出我正确的方向。
【问题讨论】:
-
@HAL9256 - 为什么不将其标记为 ETL?
-
服务器运行的是什么版本的 SharePoint?
-
Sharepoint 2007。我找到了另一种获取 csv 的方法:我通过 Access 链接到 SharePoint 列表,并使用 WinHttpReq 通过提供其 URL 来下载文件。但是,如果您知道使用 PowerShell 从 Outlook 获取文件的方法,我仍然很想知道。
标签: sharepoint powershell outlook etl