问题描述
我是 Powershell 的新手(以及一般的编码),我正在尝试从特定发件人处以 .xlsx 格式保存 Outlook 附件。我设法编写了一个通用脚本来保存来自发件人的附件,但我还想解析附件名称以使用解析的组值将其与特定标题一起保存。
示例前景附件名称:生产价格变化 1-1 for-#70-Butte.xlsx
这是有效的通用脚本:
#Open outlook and define MAPI environment
$outlook = new-object -com outlook.application
$namespace = $outlook.GetNamespace("MAPI")
#Define InBox as an Object the "1" denotes the second listed account (pricing email account)
$inBox = $outlook.Session.Folders.Item(1).folders.item("InBox")
$inBox | ft Folderpath
#Define Cody Subfolder as an object
$Cody = $Outlook.Session.Folders.Item(1).Folders.Item("InBox").folders.item("Cody")
$Cody | ft FolderPath
$Cody.Items | Select-Object Sendername,senderemailaddress -unique
#Define save location
$filepath = "C:\Users\cody.weisz\Desktop\Produce"
$Cody.Items | where-object {$_.Sendername -match "Jeff Griffin"} | Foreach {
$_.attachments | Foreach {
Write-Host $_.filename
$name = $_.filename
If($name.contains("xlsx")) {
$_.saveasfile((Join-Path $filepath "$name.xlsx"))}}}
$filepath = "C:\Users\cody.weisz\Desktop\Produce"
$Cody.Items | where-object {$_.Sendername -match "Jeff Griffin"} | Foreach {
$_.attachments | Foreach {
Write-Host $_.filename
$name = $_.filename | Foreach {
Select-string -Pattern (^(\w+\s\w+\s\w+\s)(\d+-\d+)(\w+-)(\W\d+)) |
ForEach-Object {
$Type,$Date,$NA,$Store = $_.Matches[0].Groups[1..4].Value
[PSCustomObject] @{
Type = $Type
Date = $Date
NA = $NA
Store = $Store
If($name.contains("xlsx")) {
$_.saveasfile((Join-Path $filepath "$Type+$Store+$Date.xlsx"))}}}}}}
非常感谢任何帮助。谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)