【问题标题】:Checking mailbox attribute and adding value if null检查邮箱属性并在 null 时添加值
【发布时间】:2015-05-25 12:40:34
【问题描述】:

我想检查一个组织中所有邮箱的属性;如果值为空,那么我想添加一个属性(电子邮件地址)

get-mailbox -Organization test.me.net |
if (-ForwardingSmtpAddress -eq {})
{
Set-Mailbox -DeliverToMailboxAndForward $true -ForwardingSmtpAddress admin@test.me.net
}

我收到的错误信息是...

“if”一词未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查拼写 名称,或者如果包含路径,请验证路径是否正确,然后重试。 在 C:\Scripts\smtpaddress.ps1:2 char:3 + 如果

有什么办法可以解决这个问题吗?

感谢您的阅读,科尔姆

【问题讨论】:

    标签: powershell exchange-server


    【解决方案1】:

    使用 Filter 参数获取在 ForwardingSmtpAddress 属性中没有值的邮箱,将结果通过管道传送到 Ste-Mailbox 并设置 DeliverToMailboxAndForward 和 ForwardingSmtpAddress 参数。请记住,所有邮箱都会将电子邮件转发到管理员邮箱。:

    Get-Mailbox -ResultSize Unlimited -OrganizationalUnit me.net/test -Filter {ForwardingSmtpAddress -eq $null} | Set-Mailbox -DeliverToMailboxAndForward $true -ForwardingSmtpAddress admin@test.me.net
    

    【讨论】:

    • 非常感谢 Shay 只是用 ) 而不是 } 的错字;效果很好!! :)
    【解决方案2】:

    如果你像这样通过管道将它传递给 For-Each,你可以在每个上做一个 if:

    get-mailbox | % {
    if ($_.ForwardingSmtpAddress -eq {})
    {
    *Do something*
    }
    }
    

    但您可能应该只使用过滤器并将结果通过管道传输到 set-mailbox 命令(问号代表 Where-Object):

    get-mailbox | ? {$_.ForwardingSMTPAddress -eq {}} | Set-Mailbox......
    

    【讨论】:

      【解决方案3】:

      我编写了一个脚本,用于为那些没有应用的人启用保留策略。

      Get-Mailbox -filter {retentionpolicy -eq $null} | Set-Mailbox -retentionpolicy "120DayRetention Policy"

      工作就像一个魅力。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-03-25
        • 1970-01-01
        • 1970-01-01
        • 2013-02-01
        • 2023-03-20
        • 2019-02-13
        • 2016-11-15
        • 1970-01-01
        相关资源
        最近更新 更多