【问题标题】:Powershell script to return only totalitems from and exchange 2003 mailboxPowershell脚本仅从2003邮箱返回totalitems并交换2003邮箱
【发布时间】:2012-10-23 14:44:49
【问题描述】:

我正在编写一个仅返回来自 Exchange 2003 邮箱的全部项目的 Powershell 脚本。到目前为止,我有这个:

get-wmiobject -computername exchange01 -namespace root\microsoftexchangev2 -class exchange_mailbox -filter "mailboxdisplayname='Journal Mail'" |选择对象总数 |写主机

但是这给出的结果是:

@{totalitems=939}

我只想返回这个数字,因为我们有一个外部程序会读取这个数字并在它超过预定数字时发送通知。

我很难找到从结果中去除所有不必要信息的方法。欢迎对我如何实现这一点提出任何建议。

【问题讨论】:

    标签: powershell scripting


    【解决方案1】:

    Select-Object 返回一个具有一个属性的对象,将结果赋值给一个变量并引用属性名:

    $mbx = get-wmiobject -computername exchange01 -namespace root\microsoftexchangev2 -class exchange_mailbox -filter "mailboxdisplayname='Journal Mail'" 
    $mbx.totalitems
    

    【讨论】:

      【解决方案2】:

      试试这是否可行:

      get-wmiobject -computername exchange01 -namespace root\microsoftexchangev2 -class exchange_mailbox -filter "mailboxdisplayname='Journal Mail'" | select-object -ExpandProperty totalitems 
      

      【讨论】:

      • @ShayLevy 感谢您修复“--”!
      猜你喜欢
      • 2010-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多