2016-06-09 31 views
0

我想從Outlook中的電子郵件中提取.xls文件,將其重命名並將其保存到文件夾中。我找到了一些腳本,但是其中沒有一個腳本完全按照我的需要實現。從Outlook中提取並重命名.xls的Powershell腳本

已更新。

我發現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 '[email protected]' }; 
$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中,是否可以通過調整此腳本來訪問 公用文件夾內的文件夾?

回答

0

不知道你怎麼想的重命名,但這裏是一個counter++例如:
foreach語句添加一個新的變量:

$counter=0 

然後在foreach未來1

增加做
$counter++ 

最後重命名提取的文件,像這樣

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

更好的是給出一個帶有2個真實文件名的例子,並告訴你如何期待輸出

相關問題