ConsoleApplication:
class Program
{
static void Main()
{
using (var runSpace = RunspaceFactory.CreateRunspace())
{
runSpace.Open();
runSpace.SessionStateProxy.SetVariable("Var1", "Alex");
using (var pipeline = runSpace.CreatePipeline("C:\\P.ps1"))
{
pipeline.Invoke();
}
}
}
}
P.ps1
$logFile = "C:\MyLog.txt"
function Write-Log ([string] $message)
{
Add-Content -Path $logFile -Value $message
}
Write-Log "Var1: " + $Var1
「Var1:Alex」がログファイルに書き込まれると思いますが、「Var1:」を取得します。
私は何を間違えましたか?
編集:
私の元の問題は次のサイトにあります:http://nugetter.codeplex.com/workitem/31555