【问题标题】:Retrieving Office 365 Exchange Quarantine Sender and Receiver with Powershell使用 Powershell 检索 Office 365 Exchange 隔离发件人和收件人
【发布时间】:2019-04-27 21:21:25
【问题描述】:

我一直在尝试使用 Powershell 从 Office 365 Exchange 检索基本信息,但我似乎无法在一个命令中获得所有我想要的信息。

如果我使用:

Get-QuarantineMessage -SenderAddress send@domain1.tld -RecipientAddress receive@domain2.tld | Select-Object Identity,SenderAddress,RecipientAddress,Subject,QuarantineTypes,Direction,Expires

我得到了我想要的一切,除了 RecipientAddress:

Identity         : eafc9e23-8c21-7a40-2d92-41a9a402abe5\e62c7c5b-7da4-2b79-        
e5f4-b902fc927429
SenderAddress    : send@domain1.tld
RecipientAddress : {}
Subject          : Downtown Events
QuarantineTypes  : Spam
Direction        : Inbound
Expires          : 5/3/2019 1:00:00 PM

我必须在 for 循环中使用相同的命令两次才能得到它:

(Get-QuarantineMessage -SenderAddress send@domain1.tld -RecipientAddress receive@domain2.tld).Identity | ForEach-Object {Get-QuarantineMessage -Identity $_ | Select-Object Identity,SenderAddress,RecipientAddress,Subject,QuarantineTypes,Direction,Expires} 

Identity         : eafc9e23-8c21-7a40-2d92-41a9a402abe5\e62c7c5b-7da4-2b79-e5f4-b902fc927429
SenderAddress    : send@domain1.tld
RecipientAddress : {receive@domain2.tld}
Subject          : Downtown Events
QuarantineTypes  : Spam
Direction        : Inbound
Expires          : 5/3/2019 1:00:00 PM

我觉得必须有更好/更优雅的方式来执行此操作,然后运行相同的命令两次。

【问题讨论】:

    标签: powershell exchange-server


    【解决方案1】:

    我自己无法对此进行测试,但在我看来,您已经拥有 RecipientAddress 并且正在通话中使用它。

    也许,这样可以避免你两次调用相同的命令:

    $recipient = 'receive@domain2.tld'
    Get-QuarantineMessage -SenderAddress send@domain1.tld -RecipientAddress $recipient | 
        Select-Object Identity,SenderAddress,
                      @{Name = 'RecipientAddress'; Expression = {$recipient}},
                      Subject,QuarantineTypes,Direction,Expires
    

    【讨论】:

    • 谢谢,效果很好。不过您能解释一下@{} 部分的工作原理吗?
    • @yito @{} 部分称为Calculated Property。使用哈希表的语法,您可以创建从其他属性或变量派生的属性,并为它们提供您选择的名称。在Expression = {} 部分,你可以给它任何你需要的值。附:如果您觉得我的回答解决了您的问题,请考虑点击左侧的✓ 接受回答。这将帮助其他有类似问题的人更容易地找到它,并且作为我的额外动力,它将增加我的代表。 ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    • 2020-10-02
    • 1970-01-01
    相关资源
    最近更新 更多