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 文字列を次のように渡します。

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

しかし、これは良くない結果です。まず、PowerShell は正規表現パターン パラメータのエラーを取得しますか? パラメータ文字列で正規表現パターンを渡すにはどうすればよいですか? 2 番目に、部分文字列の powershell get エラーに文字 "-" が含まれています。手伝って頂けますか?

4

1 に答える 1

0

一重引用符ではなく、バックティックで二重引用符をエスケープします。

-a "-n:10 -r:`".*?.`" -l:`"blabla string with spaces`""
于 2012-10-29T11:52:17.233 に答える