2014-10-27 50 views
0

單一的PowerShell命令我試圖運行運行與管

powershell.exe -command "Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn; Get-MailboxExportRequest -Status Completed | Remove-MailboxExportRequest" 

但由於某些原因,該命令掛起(大概管道被不同的解釋)。有什麼辦法可以將它作爲管道而不是邏輯或?

+0

當您僅在PowerShell會話中嘗試時會發生什麼?將認爲這個問題是與'Add-PSSnapin' – Matt 2014-10-27 19:56:40

回答

0

-command參數用一個腳本塊,eiter在這樣的字符串定義它:

powershell.exe -command "& {Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn; Get-MailboxExportRequest -Status Completed | Remove-MailboxExportRequest}" 

或者只是使用一個腳本塊擺在首位:

powershell.exe -command {Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn; Get-MailboxExportRequest -Status Completed | Remove-MailboxExportRequest } 

的最好辦法,雖然是把它放在腳本文件中並使用-file參數。如果你使用這個計劃任務(只是一個猜測),我建議你做後者。

+0

這不是真的。從[TechNet](http://technet.microsoft.com/en-ca/library/hh847736.aspx):執行指定的命令(以及任何參數),就像它們在Windows PowerShell命令提示符下輸入一樣,然後退出,除非NoExit參數被指定._。你應該可以在其中放置一個scriptblock。 – Matt 2014-10-27 19:55:13

+0

我看到鏈接的感謝 – Paul 2014-10-27 20:34:25