【问题标题】:Powershell script to extract and rename .xls from outlook用于从 Outlook 中提取和重命名 .xls 的 Powershell 脚本
【发布时间】:2016-10-09 16:48:21
【问题描述】:

我想从 Outlook 中的电子邮件中提取 .xls 文件,将其重命名并将其保存到文件夹中。我找到了一些脚本,但没有一个是根据我的需要完全实现的。

帖子已更新。

我找到了this one,但它没有重命名,是否可以修改此代码以满足我的要求?

#file path
$filepath = “c:\test”


#set outlook to open
$o = New-Object -comobject outlook.application
$n = $o.GetNamespace(“MAPI”)


#you'll get a popup in outlook at this point where you pick the folder you want to scan
$Account = $n.Folders | ? { $_.Name -eq 'name@domain.com' };
$Inbox = $Account.Folders | ? { $_.Name -match 'Inbox' };
$f = $Inbox.Folders | ? { $_.Name -match 'subfolder' };

#string to search for in attachment name
$file = '.xlsx'


#now loop through them and grab the attachments
$f.Items | foreach {
    $_.attachments | foreach {
    Write-Host $_.filename
    $a = $_.filename
    $b = 'Rename ' + $a
    If ($a.Contains($file)) {

    $_.saveasfile((Join-Path $filepath $b))
      }
  }

}

帖子已更新。

此脚本适用于我自己的邮箱。我虽然有一个公共文件夹 添加到我的 Outlook 中,是否可以访问 通过调整此脚本来创建公共文件夹?

【问题讨论】:

    标签: excel email outlook powershell-2.0 extract


    【解决方案1】:

    不确定您希望如何重命名,但这里有一个 counter++ 示例:
    foreach语句之前添加一个新变量:

    $counter=0
    

    然后在foreach中做next加1

     $counter++ 
    

    最后像这样重命名提取的文件

    $_.saveasfile((Join-Path $filepath "file$counter.xlsx"))
    

    最好是举一个有 2 个真实文件名的例子,并告诉你如何期望输出

    【讨论】:

      猜你喜欢
      • 2014-03-02
      • 1970-01-01
      • 2015-06-03
      • 1970-01-01
      • 1970-01-01
      • 2022-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多