簡體   English   中英

如何從批處理文件自動運行交換 powershell 命令

[英]How to run exchange powershell command automatically from batch file

我有一個包含以下代碼的.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文件在交換 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"

我解決了:我需要使用; 第一個命令后的符號表示當前命令的結束。 然后我就可以毫無問題地執行下一個命令。

完整的工作代碼:

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' "

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM