2013-02-17 99 views

回答

1

這樣的:使用調用表達可以是一種選擇

PowerShell.exe -Command "dir z:\test -fi "*.tmp" -r | ?{$_.creationtime -le (Get-Date).adddays(-30)} | del" 
0

PowerShell -Command {Invoke-Expression "dir z:\test -fi `"*.tmp`" -r | ?{`$_.creationtime -le (Get-Date).adddays(-30)} | del"} 
1

另一種可能是編碼的命令:

$command = "dir z:\test -fi '.tmp' -r | ?{$_.creationtime -le (Get-Date).adddays(-30)} | del " 
$bytes = [System.Text.Encoding]::Unicode.GetBytes($command) 
$encodedCommand = [Convert]::ToBase64String($bytes) 

powershell.exe -encodedCommand $encodedCommand 
2

命令參數可以接受腳本塊以及字符串,在您的頂級示例{}中表示腳本塊。所以只需將命令放在「」而不是{}中。

PowerShell.exe -Command "dir z:\test -fi "*.tmp" -r | ?{$_.creationtime -le (Get-Date).adddays(-30)} | del" 

要記住的唯一的事情是,如果你將它指定爲類似上面的字符串命令必須是你因爲一切都指定它被解釋爲要運行該命令後,最後一個參數。

相關問題