2012-10-29 38 views
1
Param(
[alias("sp")] 
[string]$script_path, 
[alias("a")] 
[string]$args, 
[alias("u")] 
[string]$user_name, 
[alias("p")] 
[string]$password, 
[alias("h")] 
[string]$host_name 
) 
$pass = convertto-securestring $password -asplaintext -force 
$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user_name,$pass 
if ($args -ne "") 
{ 
$script_path += $args 
} 
invoke-command -credential $mycred -computername $host_name -filepath $script_path 

我使用這個腳本的遠程執行其他腳本定位在$ script_path,並嘗試通過ARGS字符串作爲通ARGS字符串遠程執行

-a "-n:10 -r:'".*?.'" -l:'"blabla string with spaces'"" 

但這不是好的結果。 首先,PowerShell的正則表達式模式參數獲取錯誤? 我如何傳遞參數字符串中的正則表達式模式? 其次,powershell get substring中的錯誤包含char「 - 」。你可以幫我嗎?

回答

0

你逃跑用反單引號,不是單引號雙引號:

-a "-n:10 -r:`".*?.`" -l:`"blabla string with spaces`""