【问题标题】:How to run exchange powershell command automatically from batch file如何从批处理文件自动运行 Exchange Powershell 命令
【发布时间】:2020-01-29 12:55:18
【问题描述】:

我有一个带有以下代码的.bat 文件:

START C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -version 2.0 -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto"

上面的代码将成功启动一个新的powershell主机,然后连接到我的交换服务器。

如何从同一个batch 文件在exchange powershell 主机中运行以下命令? (基本上我正在尝试自动化该过程)

Get-MessageTrackingLog -resultsize unlimited -start "01/01/2020 00:00:00" -Server hermod -EventId Deliver | where {[string]$_.sender -like '*@gmail.com'} | where {[string]$_.Recipients -like '*@gmail.com'} > "C:\MailReporter\Output\emails.txt"

【问题讨论】:

    标签: powershell exchange-server-2010


    【解决方案1】:

    我解决了:我需要在第一个命令之后使用; 符号来表示当前命令的结束。然后我能够毫无问题地执行下一个命令。

    完整的工作代码:

    START C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -version 2.0 -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; Get-MessageTrackingLog -resultsize unlimited -start '01/09/2019 00:00:00' -Server hermod -EventId Deliver | where {[string]$_.sender -like '*@gmail.co.uk'} | where {[string]$_.Recipients -like '*@gmail.co.uk'} > 'C:\MailReporter\Output\emails.txt' "
    

    【讨论】:

      猜你喜欢
      • 2011-08-27
      • 2018-02-14
      • 1970-01-01
      • 2016-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-15
      • 1970-01-01
      相关资源
      最近更新 更多