我编写了一个 PowerShell 脚本来删除在我的 Outlook 配置文件中打开的辅助邮箱的所有电子邮件和收件箱子文件夹,但保留用户邮箱的其余部分完好无损。我想知道是否有办法在不先将所有内容发送到“已删除邮件”文件夹的情况下做到这一点。
我正在通过 VPN 远程工作,而将文件移动到我的删除项目中这一不必要的步骤既慢又令人讨厌的不便。有没有相当于Shift+的脚本Delete?
Get-Member 返回邮件项目对象类型的以下方法列表。我一直在使用 Delete 方法,但我在 MSDN 上找不到对象类型引用来仔细查看它的方法,例如,Delete 是否会采用参数来永久删除。
TypeName: System.__ComObject#{00063034-0000-0000-c000-000000000046}
Name MemberType Definition
---- ---------- ----------
AddBusinessCard Method void AddBusinessCard (ContactItem)
ClearConversationIndex Method void ClearConversationIndex ()
ClearTaskFlag Method void ClearTaskFlag ()
Close Method void Close (OlInspectorClose)
Copy Method IDispatch Copy ()
Delete Method void Delete ()
Display Method void Display (Variant)
Forward Method MailItem Forward ()
MarkAsTask Method void MarkAsTask (OlMarkInterval)
Move Method IDispatch Move (MAPIFolder)
PrintOut Method void PrintOut ()
Reply Method MailItem Reply ()
ReplyAll Method MailItem ReplyAll ()
Save Method void Save ()
SaveAs Method void SaveAs (string, Variant)
Send Method void Send ()
ShowCategoriesDialog Method void ShowCategoriesDialog ()
我的脚本现在看起来像这样:
# Initialise variables
$TargetMailbox = "Mailbox - User"
# SCRIPT BODY
# ===========
# Connect to Outlook
$Outlook = New-Object -comobject Outlook.Application
# Select the mailbox by name
$Mailbox = $Outlook.Session.Folders | Where-Object { $_.Name -eq $TargetMailbox}
# Select Inbox by name
$Inbox = $Mailbox.Folders | Where-Object { $_.Name -eq "Inbox" }
# Delete subfolders
$Inbox.Folders | foreach {
write-host "Deleting Inbox\$($_.Name) (Folder)"
$_.Delete()
}
# Delete items
$Inbox.Items | foreach {
write-host "Deleting Inbox\$($_.subject) (Item)"
$_.Delete()
}