我在一个文件夹中收到了100多封电子邮件,所有这些邮件都有附件。我想创建一个包,它将从一个excel表中的所有电子邮件附件中复制数据,并添加一个列,该列将根据数据收到这些电子邮件的收到日期。任何人都可以指导我如何在ssis的帮助下完成它封装
答案 0 :(得分:0)
不是ssis但它应该产生所需的结果。只需更改最后一行的路径即可。
function Get-Attachment
{
[CmdletBinding()]
Param
(
[Parameter(ParameterSetName="Path", Position=0, Mandatory=$True)]
[String]$Path,
[Parameter(ParameterSetName="LiteralPath", Mandatory=$True)]
[String]$LiteralPath,
[Parameter(ParameterSetName="FileInfo", Mandatory=$True, ValueFromPipeline=$True)]
[System.IO.FileInfo]$Item
)
Begin
{
remove-item $Path\attachments.xlsx
$outlook = New-Object -ComObject Outlook.Application
$excel = New-Object -ComObject Excel.Application
$excel.visible = $true
$workbook = $excel.Workbooks.add()
$s1 = $workbook.Sheets.add()
$s1.name = "Attachments"
$cells= $s1.Cells
$s1.range("A1:A1").font.bold = "true"
$s1.range("A1:A1").cells="RecDate"
$s1.range("B1:B1").cells="Data"
$s1.range("B1:B1").font.bold = "true"
}
Process
{
switch ($PSCmdlet.ParameterSetName)
{
"Path" { $files = Get-ChildItem -Path $Path }
"LiteralPath" { $files = Get-ChildItem -LiteralPath $LiteralPath }
"FileInfo" { $files = $Item }
}
$row=2
$col=2
$files | % {
$msgFn = $_.FullName
if ($msgFn -notlike "*.msg") {
return
}
$msg = $outlook.CreateItemFromTemplate($msgFn)
$rdate = $msg.ReceivedTime
$msg.Attachments | % {
$attFn = $msgFn -replace '\.msg$', " - Attachment - $($_.FileName)"
if (Test-Path -literalPath $attFn) {
return
}
$_.SaveAsFile($attFn)
Get-ChildItem -LiteralPath $attFn
$d = ( Get-Content -Path $attFn -Raw)
$cells.item($row,$col)=$d.ToString()
$cells.item($row,1) = $rdate
$row++
}
$s1.range("A1:B1").EntireColumn.autofit() | out-Null
$s1.range("A1:B1").EntireColumn.WrapText = $false | out-Null
}
}
End
{
$workbook.SaveAs("$Path\attachments.xlsx")
}
}
Get-Attachment -Path C:\Users\Administrator\pathtodir\